Dear All,
Is it possible to write a SAS Program to read the nth observation from a dataset by Direct Access ?
Thanks a lot in advance for help.
Regards,
S Ravuri.
every 3rd record.
data foo;
do _n_=1 to 19 by 3;
set sashelp.class point=_n_;
output;
end;
stop;
run;
NOTE: The data set WORK.FOO has 7 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
only the 5th record.
data foo;
_n_=5;
set sashelp.class point=_n_;
output;
stop;
run;
NOTE: The data set WORK.FOO has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Please give me the answer:
1: SAS program to read alternative observations from a datasset by direct access?
2: SAS program to read 5th 8th and 10th obesrvations from a datasset by direct access?
There may be a simpler way, but this is how I like to approach it.
data foo;
*get obs 5,8,10 of 10 obs cycle;
*n[0] tracks position through cycle;
*n[1]-n[3] hold interation movement;
*_n_ start at 5, then move by n[1]=3 to 8,
* then move by n[2] to 10,
* then move by n[3] to 15,
*reset n[0]=1, repeat;
array n[0:3] _temporary_ ( 1 3 2 5 );
do _n_=5 by n[n[0]] while( _n_ <= nobs );
set sashelp.shoes nobs=nobs point=_n_;
n[0] = ifn( n[0]=3 , 1 , n[0]+1 );
output;
end;
stop;
run;
/* for nth observation of different group in same data set*/
data ds1 drop(var1);
set ds2;
By var_name;
retain var1;
if first.var_name=1 and last.var_name=0 then var1=0;
var1+1;
if var1=nth_observation then output;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: