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

 

following data step extracting data from 5th observation to 10th observation from datafile

 

data newfile;
set datafile;
if _N_ in (5,6,7,8,9,10,11,12,13,14) then output;

run;

 

I am trying same output using macros but it could not give result

I use %obs()

 

any one can help me on this 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

An example for dynamic code expanded from the current one:

%macro mymac(fobs,lobs);

data newfile;
set datafile (firstobs=&fobs. obs=&lobs.);
run;

%mend;

%mymac(5,14)

The "action" is still in the data step, but the parameters are now dynamic.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Much better do do it with the respective dataset options:

data newfile;
set datafile (firstobs=5 obs=14);
run;

You do not do data manipulation with the macro preprocessor. The macro preprocessor is for creating dynamic code. So unless there is something in this code that you want to make dynamic, there is no need for macro processing.

uspanchal
Fluorite | Level 6

Yes it is much better and easy

 

thanks a lot sir.

Kurt_Bremser
Super User

An example for dynamic code expanded from the current one:

%macro mymac(fobs,lobs);

data newfile;
set datafile (firstobs=&fobs. obs=&lobs.);
run;

%mend;

%mymac(5,14)

The "action" is still in the data step, but the parameters are now dynamic.

uspanchal
Fluorite | Level 6

 

same result appear as you code in macros

thanks a lot

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Discussion stats
  • 4 replies
  • 756 views
  • 2 likes
  • 2 in conversation