BookmarkSubscribeRSS Feed
Rik
Calcite | Level 5 Rik
Calcite | Level 5
I want to create a variable where the name should contain the value of another variable.

Example :

A=1;
Within 1 data step, I want to create variable "SCALE1" where 1 represents the value of variable A.

Any suggestion is welcome
4 REPLIES 4
deleted_user
Not applicable
Rik,

Try this:

data new;
A=1;
IF A = 1 THEN CALL SYMPUT('var1','scale'||LEFT(PUT(A, 3.)));
&var1 =45;
run;

proc print data=new;
run;
Rik
Calcite | Level 5 Rik
Calcite | Level 5
a Message was edited by: Rik
Rik
Calcite | Level 5 Rik
Calcite | Level 5
Hi Nilan,

This seems to be working fine in the example you posted but I also want to make it work in following example :
data test;
a=1;output;
a=2;output;
a=3;output;
run;
data new;
set test;
......
run;

Unfortunally your solution does not cover this...
But thanks for the effort.
1162
Calcite | Level 5
I have two thoughts on this topic.

1) In the first solution, I'm surprised that call symput worked. I thought that variable assignment could not be used in the data set in which it was assigned. When I try the code myself, I get an error.

2) It sounds like you want to take a list of data and transpose it into a set of columns with the column name defined, in part, by a variable. To do this, I would suggest looking at the prefix option of PROC TRANSPOSE.

data test;
a=1;b=45; output;
a=2;b=27; output;
a=3;b=99; output;
run;

proc transpose data=test out=new prefix=Scale;
id a;
var b;
run;

proc print data=new; run;

Hope this helps.

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!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 4 replies
  • 1086 views
  • 0 likes
  • 3 in conversation