BookmarkSubscribeRSS Feed
WAL83
Obsidian | Level 7
I have a dataset similar to:

age frequency
20 2
21 3
23 5
24 3

and I want to create a new dataset from the above dataset that looks like:

age frequency
20 1
20 1
21 1
21 1
21 1
23 1
23 1
23 1
23 1
23 1
24 1
24 1
24 1

How can I accomplish this. Thanks.
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
Inside a DATA step program, you would need to use a DO loop. If you want the value of the FREQUENCY variable to change to 1, then you'd probably need to save the original value within your DATA step logic. Something like this untested code shown below.

cynthia
[pre]
DATA new;
. . . more code to read data either with INFILE/INPUT or SET statement . . .
. . . may also want KEEP or DROP statement here . . .

** grab original frequency value into new variable name;
orig_frequency = frequency;

** set frequency value to 1;
frequency=1;

** Use original frequency value in do loop for output;
** control output in DO loop -- one observation will be output;
** for every iteration of the DO loop.;
do i = 1 to orig_frequency;
output new;
end;
. . . more code to end program . . .
run;
[/pre]
WAL83
Obsidian | Level 7
Thanks Cynthia. I'll give it a shot.
WAL83
Obsidian | Level 7
Thanks Cynthia. It worked perfectly 🙂

proc import out=data
datafile= "c:\file.xlsx"
dbms=excel replace;
range="Sheet1$";
getname=yes;
mixed=no;
scantext=yes;
usedate=yes;
scantime=yes;
run;

data data1;
set data;
orig_frequency=frequency;
frequency=1;
do i = 1 to orig_frequency;
output data1;
end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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