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

*Working code...;

 

data test;
set ssh.sshbindicatorstable28jul2016;
run;
 
proc contents data=test; run;
 
proc sort data =test;
by hsnum year sex age arhsres: wt: disadvqt denom schpatt sch supptype year: agegrp region
ariaplusc lhd10 phn_2015_code pcode pcoderes indigene;
run;
 
Data m_mental5 (keep= hsnum year sex age arhsres: wt: disadvqt denom schpatt sch supptype year: agegrp region
                             ariaplusc lhd10 phn_2015_code pcode pcoderes indigene m_mental5 m_mental5_txt);
set test;
m_mental5_txt_1=m_mental5_1_txt;
m_mental5_txt_2=m_mental5_2_txt;
m_mental5_txt_3=m_mental5_3_txt;
m_mental5_txt_4=m_mental5_4_txt;
m_mental5_txt_5=m_mental5_5_txt;
m_mental5_txt_6=m_mental5_6_txt;
m_mental5_txt_7=m_mental5_7_txt;
m_mental5_txt_8=m_mental5_8_txt;
array a (8) m_mental5_1-m_mental5_8;
array b (8) m_mental5_txt_1-m_mental5_txt_8;
do i=1 to 8;
   m_mental5= a(i);
   m_mental5_txt=b(i);
if not missing (m_mental5_txt) then output;
end;
run;
 
*Macro code generating error;
%macro multiresponse (ds=);
 
Data &ds (keep= hsnum year sex age arhsres: wt: disadvqt denom schpatt sch supptype year: agegrp region
                             ariaplusc lhd10 phn_2015_code pcode pcoderes indigene &ds &ds._txt);
set test;
 
%do i=1 %to 8;
  &&ds_txt_i=&&ds_i_txt;
  %end;
run;
array a (*) &ds_1-&ds_8;
array b (*) &ds._txt_1-&ds._txt_8;
do i=1 to dim(&ds._txt_8)
    &ds= a(i);
     &ds_txt=b(i);
if not missing (&ds._txt) then output;
run;
end;
%mend;
 
%multiresponse (ds=m_mental5);
 
 *Also tried using transpose but again generating error;
 
%macro msh(ds=, vars=);
proc transpose data=test out=&ds (drop=_name_ rename=(_label_=Category Col1=Value));
by hsnum year sex age arhsres: wt: disadvqt denom schpatt sch supptype year: agegrp region
ariaplusc lhd10 phn_2015_code pcode pcoderes indigene;
VAR &vars;
run;
%mend;
 
%msh(ds=m_mental5, vars=&ds1 &ds2 &ds3 &ds4);
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Everything @LinusH and @RW9 said.

 

...but what certainly will throw an error is a "run" statement in the middle of a data step

*Macro code generating error;
%macro multiresponse (ds=);
 
Data &ds.....
set test;
.....
run;
array a (*) &ds_1-&ds_8;
.....
run;
end;
%mend;

 ...oh... and an "end" which is not an "%end" after a "run" statement.

 

What you probably should do: Make your data step work as a sample outside of a macro and only "macrotize" it once it works. 

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

So, what's the error?

Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Lets take a step back.  Post some test data:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

With what you have, and show an example of what you want the output to look like.  Most of that code posted there looks to be redundant, but until I see input/output its hard to say.

Patrick
Opal | Level 21

Everything @LinusH and @RW9 said.

 

...but what certainly will throw an error is a "run" statement in the middle of a data step

*Macro code generating error;
%macro multiresponse (ds=);
 
Data &ds.....
set test;
.....
run;
array a (*) &ds_1-&ds_8;
.....
run;
end;
%mend;

 ...oh... and an "end" which is not an "%end" after a "run" statement.

 

What you probably should do: Make your data step work as a sample outside of a macro and only "macrotize" it once it works. 

Astounding
PROC Star

In addition, note that your definition of the elements in the array A is incorrect.  The array B is correct, but A should use similar syntax:

 

&ds._1 - &ds._2

 

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
  • 5 replies
  • 1088 views
  • 1 like
  • 5 in conversation