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
What is slibref?
How do you use the do loop if you don’t know how many times you should execute the do loop?
Name any two sas spawners? : sas-grid-administration
What are the difference between ceil and floor functions in sas?
how would you determine the number of missing or nonmissing values in computations? : Sas programming
I am preparing SAS Certified Advanced Programmer for SAS 9 in 2014. If anybody has the latest dumps for this exam, please mail me at dhiman.mukherjee@gmail.com
what is metadata? : Sas-bi
I need level 2 to 5 sas using companies in india
Do you need to compute new variables? If so,should you do this before you execute the report-writing procedure?
do you need to know if there are any missing values? : Sas programming
what is data access? : Sas-di
describe the interaction table in sas di? : Sas-di
How do you define proc in sas? : sas-grid-administration
Explain append procedure?
how does sas handle missing values in: assignment statements, functions, a merge, an update, sort order, formats, procs? : Sas programming