DATA Step, Macro, Functions and more

Array question

Reply
N/A
Posts: 0

Array question

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Array question

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.
Ask a Question
Discussion stats
  • 1 reply
  • 100 views
  • 0 likes
  • 2 in conversation