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

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