BookmarkSubscribeRSS Feed
alexjaco
Calcite | Level 5

 

How do you Convert this Excel row:

 

Test1

Test1.1

123, 124, 125, 521, 324, 432, 632, 992, 214, 215

 

Into these Excel rows:

 

Test1Test1.1123
Test1Test1.1124
Test1Test1.1125
Test1Test1.1521
Test1Test1.1324
Test1Test1.1432
Test1Test1.1632
Test1Test1.1992
Test1Test1.1214
Test1Test1.1215
10 REPLIES 10
novinosrin
Tourmaline | Level 20
data have;
infile cards dlm=', ';
input (t1-t2) ($) t3- t12;
cards;
Test1 Test1.1 123, 124, 125, 521, 324, 432, 632, 992, 214, 215
;

proc transpose data=have out=want(drop=_name_);
by t1 t2;
var t3-t12;
run;

 

PS I am assuming you want to do that in SAS and you are posting accordingly in the right forum and not MS Excel forum? 

alexjaco
Calcite | Level 5

Yes done within SAS. Can you show me how it's done within importing an excel data. It's a large file. 

novinosrin
Tourmaline | Level 20

Are you asking how to import an excel file to SAS? 

If yes, have you looked into

1.proc import

2. using import wizard point and click interface

3. libname engiine xls

and so on.

 

You may have to search online quite a bit and do some reading

alexjaco
Calcite | Level 5

No I have the data imported and I'm wondering how to manipulate the data within the data step to expand the excel cell. 

novinosrin
Tourmaline | Level 20

Aah ok,

 

data have;
infile cards dlm=', ';
input (t1-t2) ($) t3- t12;
cards;
Test1 Test1.1 123, 124, 125, 521, 324, 432, 632, 992, 214, 215
;

data want;
set have;
array j t3-t12;
do over j;
want=j;
output;
end;
keep t1 t2 want;
run;

alexjaco
Calcite | Level 5

The data is more complicated than that. Here's a better sample of the data. This goes on for 40,000+ excel lines.

 

Name1Name1.199201, 99202, 99203, 99204, 99205, 97813, 97814, 97810, 97811
Name1Name1.299205, 99211, 97813, 97814, 97810, 97811
Name2Name2.1S5101, S5102, S5105
novinosrin
Tourmaline | Level 20

Oh well, i see your num values are all in a one variable seperated by comma as delimiter

 

Alll you need to do is scan one by one in a loop   and output for each scan.

 

data have;
infile cards truncover;
input t1 $ t2 $ num  $100.;
cards;
Name1	Name1.1	99201, 99202, 99203, 99204, 99205, 97813, 97814, 97810, 97811
Name1	Name1.2	99205, 99211, 97813, 97814, 97810, 97811
Name2	Name2.1	S5101, S5102, S5105
;

data want;
set have;
k=countw(num,',');
do i=1 to k;
want=scan(num,i,',');
output;
end;
keep t: want;
run;

 

 

 

novinosrin
Tourmaline | Level 20

I can only test with the sample you post. So you may have to adjust to your real data accordingly.

alexjaco
Calcite | Level 5

I figured it out! Thanks for your help!

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