how to obtain last ‘n’ observation from a dataset—
The step to obtain last observation can be done in data step by using the following code since there are no options for obtaining last ‘n’ observations (like obs which indicates last obs to be read starting from first and firstobs which indicates starting obs , there is no lastobs option which takes us to the last starting from any observation in between)
data data1;
set vikas.health_data nobs=tot;
if _n_ gt( tot-5) then output data1;
run;
outputs—
Obs subj dob visitdate lastdate age agetoday
1 011 21FEB1980 16APR1960 28OCT2001 25 13
2 012 18MAY1981 19MAY1963 20DEC2000 24 12
3 013 24JAN1983 21JUN1964 21SEP2000 22 10
4 014 25SEP1984 25OCT1968 23OCT2003 21 9
5 015 05NOV1976 27NOV1970 24NOV2006 29 17
hi, let us study how to generate different report formats in sas using different techniques and sas procedures..we will also learn how to customize the layout of the reports as per the requirement using the power of sas.. Discalimer-:This blog is for sharing the knowledge that i have gained .i do not calim the ownership of the original content that is included in the blog.SAS is a trademark of SAS ,usa.
Friday, June 5, 2009
How To obtain first n observaton in the dataset
we have the following dataset(vikas.health_data)
The SAS System 2
Obs subj dob visitdate lastdate age agetoday
1 001 21OCT1950 12MAY2003 01DEC2004 55 43
2 002 12SEP1955 10FEB1984 24MAR2002 50 38
3 003 21MAR1965 12SEP1987 25JAN2000 40 28
4 004 02AUG1975 13OCT1975 29DEC1999 30 18
5 005 04FEB1985 21AUG1980 20OCT1998 20 8
6 006 11OCT1980 10JAN1955 23MAR2001 25 13
7 007 15OCT1981 09MAR1950 12MAY2002 24 12
8 008 24OCT1956 06APR1970 01JUL2003 49 37
9 009 12JUN1954 17SEP1988 12AUG2003 51 39
10 010 16JUL1952 21FEB1955 13SEP2000 53 41
11 011 21FEB1980 16APR1960 28OCT2001 25 13
12 012 18MAY1981 19MAY1963 20DEC2000 24 12
13 013 24JAN1983 21JUN1964 21SEP2000 22 10
14 014 25SEP1984 25OCT1968 23OCT2003 21 9
15 015 05NOV1976 27NOV1970 24NOV2006 29 17
Let us suppose that you have a dataset having thousands of observation and you want to display only first few observation to save processing resources and time…
suppose the given data set is above ….it is having 15 observations.
now if we want only first 10 obs then we can use the foeelowing code in for the proc print –
proc print data=vikas.health_data (obs=10) ;
run;
the option ‘obs’ tells sas to read till 10 th observation.
Similarly , the code
proc print data=vikas.health_data ( firstobs=5 obs=10) ;
run;
outputs the observations from 5 to 10th in the dataset health_data stored in the library named vikas.
The SAS System 2
Obs subj dob visitdate lastdate age agetoday
1 001 21OCT1950 12MAY2003 01DEC2004 55 43
2 002 12SEP1955 10FEB1984 24MAR2002 50 38
3 003 21MAR1965 12SEP1987 25JAN2000 40 28
4 004 02AUG1975 13OCT1975 29DEC1999 30 18
5 005 04FEB1985 21AUG1980 20OCT1998 20 8
6 006 11OCT1980 10JAN1955 23MAR2001 25 13
7 007 15OCT1981 09MAR1950 12MAY2002 24 12
8 008 24OCT1956 06APR1970 01JUL2003 49 37
9 009 12JUN1954 17SEP1988 12AUG2003 51 39
10 010 16JUL1952 21FEB1955 13SEP2000 53 41
11 011 21FEB1980 16APR1960 28OCT2001 25 13
12 012 18MAY1981 19MAY1963 20DEC2000 24 12
13 013 24JAN1983 21JUN1964 21SEP2000 22 10
14 014 25SEP1984 25OCT1968 23OCT2003 21 9
15 015 05NOV1976 27NOV1970 24NOV2006 29 17
Let us suppose that you have a dataset having thousands of observation and you want to display only first few observation to save processing resources and time…
suppose the given data set is above ….it is having 15 observations.
now if we want only first 10 obs then we can use the foeelowing code in for the proc print –
proc print data=vikas.health_data (obs=10) ;
run;
the option ‘obs’ tells sas to read till 10 th observation.
Similarly , the code
proc print data=vikas.health_data ( firstobs=5 obs=10) ;
run;
outputs the observations from 5 to 10th in the dataset health_data stored in the library named vikas.
Tuesday, June 2, 2009
How to diplay Page Number IN ODS output

How to display pageno in output header in format ‘page x of y’ in ods —
Well this is pretty easy and can be done using the title statement itself.This always works in RTF but may not work in pdf and html..
Note the use of ods ecsapechar statement .The escapechar(or escapecharacter)is used to convey information to ods as which symbol is to be used as escapecharacter.we can use any special character as escapecharater eg #,~ etc….
ods listing close;
ods escapechar='^';
title1 "Page ^{thispage} of ^{lastpage}";
ods rtf file='c:\users\bobby\desktop\file.rtf';
ods pdf file='c:\users\bobby\desktop\file.pdf';
Proc print data=sasuser.admit n='total obs=';
Run;
ods _all_ close;
ods listing;
Monday, June 1, 2009
how to add labels to column names
How to display the number of observations in output-
Subscribe to:
Posts (Atom)
Send link to --
The Little Web Directory
Monster Directory A List Sites

