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 ae onset date n what is RDS
i have a dataset with 100 obs i want to generate title from 20th obs onwards with total observations. that should contain 100 obs.dont use firstobs and dnt split the data. use dataset block or proc report? how can we genarate;
Name types of category in which SAS Informats are placed?
how does sas handle missing values in formats? : Sas programming
Which command is used to perform sorting in sas program?
how can you create zero observation dataset? : Sas programming
what is the use of proc contents and proc print in sas? : Sas-administrator
where are dashboard components are created and maintained? : Sas-bi
Are you involved in writing the inferential analysis plan? Tables specifications?
if the Id has more then two transcatiion then show the first observation, IF Id has only two observation then It show both the observation
what is study design in while working with SAS? what are screening variables in SAS?
what has been your most common programming mistake? : Sas programming
what is sas application server, database server, sas olap server and sas metadata server? : Sas-di
what is the difference between nodup and nodupkey options? : Sas programming
Do you need to know if there are any missing values?