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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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