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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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