BookmarkSubscribeRSS Feed
JohnT
Quartz | Level 8
Hi,

I have some data in which I want to conver the value of some variables into new variables.

Here's some data:
[pre] data tmp;
input AMT01 AMT02 AMT03 AMT04 CODE01 $ CODE02 $ CODE03 $ CODE04 $;
datalines;
100 200 500 400 AB CD EF GH
100 200 500 400 AB CD IJ KL
100 200 500 400 AB EF IJ KL
;
run;[/pre]

And here's how the table looks:
[pre] AMT01 AMT02 AMT03 AMT04 CODE01 CODE02 CODE03 CODE04
100 200 500 400 AB CD EF GH
100 200 500 400 AB CD IJ KL
100 200 500 400 AB EF IJ KL[/pre]

Here's how I want that data to look:
[pre] AB CD EF GH IJ KL
100 200 500 400 . .
100 200 . . 500 400
100 . 200 . 500 400[/pre]

Is there some simple method of creating the variable names without using macros? Hopefully with a function?


Thanks. Message was edited by: John T
2 REPLIES 2
NickR
Quartz | Level 8
data tmp1;
length code $8;
set tmp;
ord=_n_;
amt=amt01;
code=code01;
output;
amt=amt02;
code=code02;
output;
amt=amt03;
code=code03;
output;
amt=amt04;
code=code04;
output;
run;

proc transpose data=tmp1 out=tmp2(drop=ord _name_);
id code;
var amt;
by ord;
run;
JohnT
Quartz | Level 8
Hi Nick R,

Thanks for your suggestion.

That works for me, now to integrate it into my job.

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