how can get the first and last observations in a dataset
using Proc SQl?

Answers were Sorted based on User's Feedback



how can get the first and last observations in a dataset using Proc SQl?..

Answer / venkatesh layam

by using monotonic function u can create first and lastobs

Is This Answer Correct ?    6 Yes 0 No

how can get the first and last observations in a dataset using Proc SQl?..

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

how can get the first and last observations in a dataset using Proc SQl?..

Answer / 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

how can get the first and last observations in a dataset using Proc SQl?..

Answer / naveen

proc sql;
select first(orderprise)
from xxx;
quit;

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SAS Interview Questions

what is the difference btw proc means and proc univariate?

8 Answers   HSBC, TCS,


At compile time when a SAS data set is read, what items are created?

5 Answers  


Hi I have list of products in a dataset, which are classified by other name for eg:- there is a product A> Malambo Shiraz Malbec 750ML(0388) which is a Red wine.Now i need to generate a report where it shows if this product appears then it should b displayed as red wine,similarly for other products and other classification. I dont wan use proc format.

4 Answers   Symphony,


describe about joins? briefly?

2 Answers   CitiGroup,


what are the considerations when picking a SAS/STAT procedure?

0 Answers   Accenture, Quintiles,






what is the use of LRECL option.

1 Answers   L&T,


This entry was posted in General. Bookmark the permalink. Post a comment or leave

0 Answers   Quintiles,


How do you connect the desktop application to metadata server? : sas-grid-administration

0 Answers  


Differences between where and if statement?

0 Answers  


If money were no object, what would you like to do?

0 Answers   Oracle,


how many types of MERGE?

17 Answers   CitiGroup,


How would you remove a format that has been permanently associated with a variable? ________________

5 Answers   Quintiles, TCS,


Categories