Macro Issue

Reply
Contributor
Posts: 27

Macro Issue

I have a situation .. i have a dataset with name File and has 450 observations. a macro needs to be written as below. Here, first parameter is dataset name and second parameter is no of obs to be read from this data set. Now i want to create datasets file file2 file3 file4 file5 having obs 1 to 100 in file1 , 101 to 200 in file2, 201 to 300 in file3 and 301 to 400 in file4 and 401 to 450 (means remaining obs)in file5. Code will  decide the no of datasets to be created at run time. Plz help guys in writing such code....

%macro mname(File,100);

code.......

%mend;

Super User
Posts: 5,437

Re: Macro Issue

Posted in reply to rohitguptaecb

And you don't have a clue on how to do this?

The forums primary objective is not distributing job tasks.

I'm pretty sure that you can do it by yourself if you consume available training, documentation and public papers.

Data never sleeps
Contributor
Posts: 27

Re: Macro Issue

I am sorry Linus that i am asking these coding parts but actually i am not that much experienced in SAS as you guys are and i tried to write this code but hanving some issues thats why i have come here to seek some help..

Super Contributor
Posts: 644

Re: Macro Issue

Posted in reply to rohitguptaecb

You might want to check the dataset options firstobs= and obs=

Richard

Respected Advisor
Posts: 4,173

Re: Macro Issue

Posted in reply to rohitguptaecb

Normally people only write macros if they need to generalize the solution for a problem and need some re-usable code. That appears not to be the case here.

Macro language can be very powerful but you should only use it if you can't solve a problem without it.

Get better at Base SAS first.

data have;
  do i=1 to 450;
    output;
  end;
run;

data want1 want2 want3 want4 want5;
  set have;
  if 1 <= _n_ <= 100 then output want1;
  else if 101 <= _n_ <= 200 then output want2;
  else if 201 <= _n_ <= 300 then output want3;
  else if 301 <= _n_ <= 400 then output want4;
  else if 401 <= _n_ <= 500 then output want5;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 189 views
  • 0 likes
  • 4 in conversation