Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

what is ae onset date n what is RDS

2497


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;

2451


Name types of category in which SAS Informats are placed?

1118


how does sas handle missing values in formats? : Sas programming

1100


Which command is used to perform sorting in sas program?

1016


how can you create zero observation dataset? : Sas programming

1103


what is the use of proc contents and proc print in sas? : Sas-administrator

1018


where are dashboard components are created and maintained? : Sas-bi

990


Are you involved in writing the inferential analysis plan? Tables specifications?

3916


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

1588


what is study design in while working with SAS? what are screening variables in SAS?

2203


what has been your most common programming mistake? : Sas programming

1059


what is sas application server, database server, sas olap server and sas metadata server? : Sas-di

984


what is the difference between nodup and nodupkey options? : Sas programming

1142


Do you need to know if there are any missing values?

1016