how can get the first and last observations in a dataset
using Proc SQl?
Answer Posted / rohitbedi
Create a new data set as below:
data demo;
input year month cpi;
datalines;
1990 6 129.9
1990 7 130.4
1990 8 131.6
1990 9 132.7
1991 4 135.2
1991 5 135.6
1991 6 136.0
1991 7 136.2
;
run;
Sort the data if needed.
Create a new id field:
data demo2;
set demo;
id = _n_;
run;
Display the first and last record for every date and finally remove the id column.
proc sql;
create table final as select * from demo2 where id in (select min(id) from demo2 group by year) or id in (select max(id) from demo2 group by year);
alter table final drop column id;
quit;
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Explain what is the use of proc gplot?
do you need to know if there are any missing values? : Sas programming
What is the basic syntax style in SAS?
Hi, Does anybody has lastest SAS certification(base, adv., clinical)dumps,if anybody has please email me at mailtorajani76@gmail.com. Thanks
What function CATX syntax does?
what is the Population you used in your project, is it ITT or PP?
which features do you use to check the data validations and errors? : Sas-administrator
How do dates work in SAS data?
What was the last computer book you purchased? Why?
Explain input and put function?
How does the internal authentication work in sas? : sas-grid-administration
which date function advances a date, time or datetime value by a given interval? : Sas programming
I have a dataset concat having a variable a b & c. How to rename a b to e & f?
What is the basic structure of the SAS base program?
how sas deals with business intelligence? : Sas-bi