DATA Step, Macro, Functions and more

Variable values into variable names

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Variable values into variable names

[ Edited ]

I have the following data:

 

lopnr  Syss1995  Syss1996  Syss1997  Syss1998  Syss1999  Syss2000     invar

      1                1                5                6               1                5                1     1996

      2                3                1                6               5                1                6     1999  

      3                1                6                1               5                6                1     1995

and so on...

 

I want a new variable with following values 

 

Syssinvar

             5

             1

             1

and so on...

 

Thus I need to get the value from the right Syss-variables with the same year as in the invar variable

My guessing is that I need to use symputx in some way, but I don't get it right. 

 

 


Accepted Solutions
Solution
Wednesday
Super Contributor
Posts: 339

Re: Variable values into variable names

Posted in reply to TobbeArbMed

Hi!

VValueX will do it Smiley Happy

 

data have;
 length lopnr syss1995 syss1996 syss1997 invar 8;
 input  lopnr syss1995 syss1996 syss1997 invar;
 datalines;
 1 1 5 6 1997
 2 3 1 6 1995
 3 1 6 1 1996
 ;
run;

data want;
 set have;
 length syssinvar 8;
 syssinvar = vvaluex(cats('syss',put(invar,best.)));
run;

View solution in original post


All Replies
Solution
Wednesday
Super Contributor
Posts: 339

Re: Variable values into variable names

Posted in reply to TobbeArbMed

Hi!

VValueX will do it Smiley Happy

 

data have;
 length lopnr syss1995 syss1996 syss1997 invar 8;
 input  lopnr syss1995 syss1996 syss1997 invar;
 datalines;
 1 1 5 6 1997
 2 3 1 6 1995
 3 1 6 1 1996
 ;
run;

data want;
 set have;
 length syssinvar 8;
 syssinvar = vvaluex(cats('syss',put(invar,best.)));
run;
New Contributor
Posts: 4

Re: Variable values into variable names

Great! Thank you!
Super User
Super User
Posts: 7,847

Re: Variable values into variable names

[ Edited ]
Posted in reply to TobbeArbMed

Looks like an array problem.

data want ;
  set have ;
  array s syss1995-syss2000 ;
  sysinvar = s(invar - 1995 +1);
run;

 

New Contributor
Posts: 4

Re: Variable values into variable names

Works perfect!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 115 views
  • 2 likes
  • 3 in conversation