BookmarkSubscribeRSS Feed
rohitguptaecb
Calcite | Level 5

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;

4 REPLIES 4
LinusH
Tourmaline | Level 20

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
rohitguptaecb
Calcite | Level 5

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..

RichardinOz
Quartz | Level 8

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

Richard

Patrick
Opal | Level 21

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 579 views
  • 0 likes
  • 4 in conversation