how can get the first and last observations in a dataset
using Proc SQl?
Answers were Sorted based on User's Feedback
Answer / venkatesh layam
by using monotonic function u can create first and lastobs
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / venkatesh layam
crate one data in sql with adding of new var (a = 1) and
sort(order by) descending order by another variable and
take distinct of a (newvar-which is already created) --then
u wil get last observation.
next do ascending and get first obs ,then union these two
data sets .u will get first and last obs.
| Is This Answer Correct ? | 0 Yes | 0 No |
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 |
How do you add a number to a macro variable?
Explain the message 'Merge has one or more datasets with repeats of by variables'.
How would you delete duplicate observations?
Which are SAS Windows Clients & SAS Java Clients
If reading an external file to produce an external file, what is the shortcut to write that record without coding every single variable on the record?
how to assign a macro value to a variable?
what is the use of sas management console? : Sas-di
who is the best SAS clinical Trainer in Hyderabad?
When looking for data contained in a character string of 150 bytes, which function is the best to locate that data: scan, index, or indexc?
How would you code a macro statement to produce information on the sas log? This statement can be coded anywhere? : sas-macro
How do you delete duplicate observations in sas?
What is the difference between an informat and a format. Name three informats or formats.