BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
surajmetha55
Fluorite | Level 6

Hi all,

 

I have a data as follow:

 

MakeModelTypeOriginDriveTrainMSRPVariable_list
Acura MDXSUVAsiaAll$36,945Make, Model, origin
Acura RSX Type S 2drSedanAsiaFront$23,820Make, Model, Type, origin

 

It has a variable called Variable_list (It has list of variable comma separated) I want to fetch value of each variable and store in one variable as show below dataset for variable " Variable_value"        

 

Expected output: 

 

MakeModelTypeOriginDriveTrainMSRPVariable_listVariable_value
Acura MDXSUVAsiaAll$36,945Make, Model, originAcura, MDX, Asia
Acura RSX Type S 2drSedanAsiaFront$23,820Make, Model, Type, originAcura,  RSX Type S 2dr, Sedan, Asia
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @surajmetha55,

 

You can apply the VVALUEX function to the variable names in Variable_list:

/* Create sample data for demonstration */

data have;
set sashelp.cars(obs=2 keep=Make--MSRP);
input Variable_list $50.;
cards;
Make, Model, origin
Make, Model, Type, origin
;

/* Create new variable containing comma-separated values according to Variable_list */

data want;
set have;
length Variable_value $100;
do _n_=1 to countw(Variable_list,',');
  Variable_value=catx(', ',Variable_value,vvaluex(scan(Variable_list,_n_,',')));
end;
run;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @surajmetha55,

 

You can apply the VVALUEX function to the variable names in Variable_list:

/* Create sample data for demonstration */

data have;
set sashelp.cars(obs=2 keep=Make--MSRP);
input Variable_list $50.;
cards;
Make, Model, origin
Make, Model, Type, origin
;

/* Create new variable containing comma-separated values according to Variable_list */

data want;
set have;
length Variable_value $100;
do _n_=1 to countw(Variable_list,',');
  Variable_value=catx(', ',Variable_value,vvaluex(scan(Variable_list,_n_,',')));
end;
run;
surajmetha55
Fluorite | Level 6

@FreelanceReinh , Thank you. Perfect solution

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1414 views
  • 5 likes
  • 2 in conversation