BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TobbeArbMed
Calcite | Level 5

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. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FredrikE
Rhodochrosite | Level 12

Hi!

VValueX will do it 🙂

 

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

4 REPLIES 4
FredrikE
Rhodochrosite | Level 12

Hi!

VValueX will do it 🙂

 

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;
TobbeArbMed
Calcite | Level 5
Great! Thank you!
Tom
Super User Tom
Super User

Looks like an array problem.

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

 

TobbeArbMed
Calcite | Level 5
Works perfect!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 4221 views
  • 2 likes
  • 3 in conversation