Hello everybody,
I will ask a question which can be little bit difficult to understand the logic. I have two different variables one of them includes four values and the other one includes three values. I need to create my desired table by using values with SAS code( You can see my desired data set in bottom). I know I can easily do it with manual( I can type the values in Excel and then Import to SAS) but I need to automatize this process.
I am not sure I can do it without Macro with multiple steps(PROC SQL or DATA STEP) or I am not sure how can I do it with macros but I tried to do it macros, I think I am close to do it, I would be so happy, if somebody can help me about it?
%LET Variable1=%STR("SECOND" "THIRD" "FOURTH");
%LET Variable2=%STR("COST" "MAIN" "AMOUNT" "SALARY");
%PUT &Variable1.;
%PUT &Variable2.;
DATA WANT;
LENGTH INFO1 $ 32 INFO2 $ 32 INFO3 $ 32;
INFILE DATALINES MISSOVER;
INPUT INFO1 INFO2 INFO3 ;
DATALINES;
FIRST COST COST
FIRST MAIN MAIN
FIRST AMOUNT AMOUNT
FIRST SALARY SALARY
RUN;
%MACRO INFO_GNR(Var1,Var2);
DATA HAVE;
LENGTH INFO1 $ 32 INFO2 $ 32 INFO3 $ 32;
INFO1=&Var1.;
INFO2=&Var2.;
INFO3=&Var2.;
RUN;
PROC APPEND DATA=HAVE BASE=WANT;
RUN;
%MEND INFO_GNR;
%MACRO LOOP_INFO_GNR;
%LET I=1;
%DO %WHILE(%SCAN(&Variable1.,&I.,%STR( ))~=);
%INFO_GNR(%SCAN(&Variable1.,&I.,%STR( )),%SCAN(&Variable2.,&I.,%STR( )));
%LET I=&I.+1;
%END;
%MEND LOOP_INFO_GNR;
%LOOP_INFO_GNR;
Desired Output;
Thanks
Why not:
data want;
length info1-info3 $8;
do info1 = "FIRST", "SECOND", "THIRD", "FOURTH";
do info2 = "COST", "MAIN", "AMOUNT", "SALARY";
info3 = info2;
output;
end;
end;
run;
Why not:
data want;
length info1-info3 $8;
do info1 = "FIRST", "SECOND", "THIRD", "FOURTH";
do info2 = "COST", "MAIN", "AMOUNT", "SALARY";
info3 = info2;
output;
end;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.