BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi I have data set like this

data var;
input Variables:$20.;
cards;
aa
bb
cc
dd
ee
ff
;;
run;

and would like to convert to something like this

LIST1 LIST2 LIST3 LIST4 LIST5 LIST6
aa,bb bb,aa
aa,bb,cc aa,cc,bb bb,aa,cc bb,cc,aa cc,aa,bb cc,bb,aa
then 4
then 5
and so on
..
..
..


Then use these list in an array to shorten the code below

data test;
set test;
if new_var in ("aa bb","bb aa") then number='01';
if new_var in ("aa bb cc","aa cc bb","bb aa cc","bb cc aa","cc aa bb","cc bb aa") then number='02';
and so on.

Thank you Message was edited by: coi
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Explore using SAS PROC TRANSPOSE to take your vertical observations and create a horizontal perspective.

Though I'm not totally clear about the origin of new_var, you can use an ARRAY declaration and reference a variable prefix, such as LIST: -- possibly to build a new CHARACTER type variable with a string-concatenation of your LIST1-LISTn variables, possibly, to use in your IF/THEN logic.

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 579 views
  • 0 likes
  • 2 in conversation