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 hierarchy flattening? : Sas-di
how would you create a data set with 1 observation and 30 variables from a data set with 30 observations and 1 variable? : Sas programming
What is the basic syntax of a sas program?
What are the different types of sas functions?
How can you create a macro variable with in data step? : sas-macro
How do you test for missing values?
What are the uses of sas?
explain the difference between proc means and proc summary?
If you have a dataset that contains 100 variables, but you need only five of those, what is the code to force SAS to use only those variables?
Why and when do you use proc sql?
What commands are used in the case of including or excluding any specific variables in the data set?
How many ways to overcome a missing values???
is data integration and etl programming is same? : Sas-di
Briefly explain input and put function?
what is the Population you used in your project, is it ITT or PP?