BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
I have a list of names (John, Jack, Tom).
I would like to create the following dataset
John 1
John 2
John 3
Jack 1
Jack 2
Jack 3
Tom 1
Tom 2
Tom 3

Any ideas? Thank you.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Sounds like a SAS examination "prep" question - suggest reviewing the DO/END statement construct in a DATA step, where you would have an outer DO/END with explicit values, and an inner DO/END code piece.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

data step programming do loop site:sas.com

do statement documentation site:sas.com
FloydNevseta
Pyrite | Level 9
The solution I offer assumes that your list of names comes from another dataset.

** create dataset of names;
data names;
input nm $ @@;
datalines;
John Jack Tom Jill Sue Bob Jennifer Tim George
;
run;


data names2;
length name $ 10;
set names;
*do nm = 'John', 'Jack', 'Tom';
do i = 1 to 3;
name = cat( strip( nm ), ' ', put( i, 1. ) );
output;
end;
*end;
keep name;
run;

If your list doesn't come from another data set and is really short, you can uncomment the DO loop and type the names like I have above. Also comment the SET statement.
gzr2mz39
Quartz | Level 8
Thank you.
This code did the job:
data names2;
set names;
do var = 1 to 3;
nm = cat( strip( name ), ' ', put( var, 1. ) );
output;
end;
keep name var;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 954 views
  • 0 likes
  • 3 in conversation