BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I want to create 10 different data sets using the data step method. The only parameter that would affect the content of the data sets is the year, 1990-1999.

Is it possible to use a do loop to create the sets (inside a data step?) or is it necessary to write a macro?

I would prefer not using a macro.

But data steps inside data steps? And the naming of the different sets?

Regards
Anne
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Yes you can, using a single DATA step, however you must list each of the 10 SAS data sets on the DATA statement for the SAS DATA step.

Explore SAS documentation and using the MDY function (within the DATA step) to assign a SAS DATE (numeric type) variable in the DO loop, incrementing the year-portion of your SAS variable via the MDY function. Apply a SAS FORMAT statement to your SAS variable.


Scott Barry
SBBWorks, Inc.
Cynthia_sas
SAS Super FREQ
Hi:
I'm not sure what you mean by using a do loop to create the data sets.
There are 2 ways to create data set with a DATA step program:
1) read "raw" data using INFILE/INPUT to create your output data set
2) read an existing SAS dataset using a SET statement (you can also read a DBMS file with the right SAS/Access product)

If you are reading data with a SET statement and you want to output to differently numbered datasets based on a value, such as YEAR,
you don't really need a do loop to accomplish this task:

[pre]
data sale93 sale94 ;
set sashelp.prdsale;
if year = 1993 then output sale93;
else if year = 1994 then output sale94;
run;

proc print data=sale93;
title '1993 Sales';
run;

proc print data=sale94;
title '1994 Sales';
run;
[/pre]

If, for example, the data had the possibility of 1990-1999, but some years were not in the data and you wanted to programmatically run a data step
program for each year, then the way to accomplish that might best be in a macro program.

It really depends on what you want to do.

cynthia

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
  • 2 replies
  • 573 views
  • 0 likes
  • 3 in conversation