BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
walterwang
Obsidian | Level 7

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?

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User
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.

ChrisNZ
Tourmaline | Level 20

@Kurt_Bremser we really need an alias  lastobs=  for the  obs=  option.

Kurt_Bremser
Super User

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.

Kurt_Bremser
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 650 views
  • 5 likes
  • 3 in conversation