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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

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