I want to get one part of the data and calculate every time. for example, first time obs: 1 to 14, second time obs: 15 to 28 etc.
I use a macro
%macro agestd_one(number);
%do i=1 %to &number %by 14;
data import;
set T0314(firstobs=&i obs=14);
run;
%end;
%mend;
I run:
%agestd_one(14);
works well.
I run:
%agestd_one(28);
error message:
ERROR: FIRSTOBS option > OBS option - no data to read from file WORK.T0314.
what wrong at here?
A suggestion for your macro:
%macro agestd_one(number);
%do start=1 %to &number %by 14;
%let end=%eval(&start+13);
data import;
set T0314 (firstobs=&start. obs=&end.);
run;
%end;
%mend;
obs=
has to contain the physical number of the last observation to be read, not the number of observations you want to read
firstobs=15 obs=28
will read 14 observations, not 28.
@Kurt_Bremser we really need an alias lastobs= for the obs= option.
You fell into a violation of the basic macro development principle: start with working code.
If you had tried
firstobs=28 obs=14
in Base SAS without the macro around it, you would have encountered the problem there, and not thought that your macro code is the culprit.
A suggestion for your macro:
%macro agestd_one(number);
%do start=1 %to &number %by 14;
%let end=%eval(&start+13);
data import;
set T0314 (firstobs=&start. obs=&end.);
run;
%end;
%mend;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.