1

I've got a macro which draws a pie chart for a provided ID. It basically chooses a row from a table, then transposes obtained one-row table and then draws a pie chart. It works perfectly fine if I call it for one observation (for ex. %StudPieChart(931123)). Here's the code:

%MACRO StudPieChart(id);
data projekt.temp;
set projekt.cwiczenia(keep=nrInd KOL1 KOL2 KOL3 aktywnosc where= (nrInd=&id));
drop nrInd;
run;

proc transpose data=projekt.temp out=projekt.temp;
run;

proc gchart data=projekt.temp;
    pie _NAME_ / sumvar=COL1 percent=inside;
run;
%MEND;

Now I want draw a chart for not one, but some sample of observations. So I generated random sample and tried to run a macro in a data step. But it doesn't work anymore and I have no clue why.

Here's the rest of code:

proc surveyselect data=projekt.cwiczenia out=projekt.sample(keep=nrInd) sampsize=5 NOPRINT;
run;


data _NULL_;
set projekt.sample;
%StudPieChart(nrInd);
run;
Joe
  • 62,789
  • 6
  • 49
  • 67
Kuba_
  • 886
  • 6
  • 22

1 Answers1

2

You can use CALL EXECUTE.

data _NULL_;
   set projekt.sample;
   call execute('%nrstr(%StudPieChart('||nrInd||'));');
   run;

RTM: http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p1blnvlvciwgs9n0zcilud6d6ei9.htm

data _null_
  • 8,534
  • 12
  • 14
  • Thanks! That works perfectly fine. But could you explain what we actually put as a argument in execute function? – Kuba_ Jan 06 '17 at 13:22
  • @Kuba_ the argument to CALL EXECUTE is a string. In your case it is %nrstr(%StudPieChart()); I left off one parenthesis in my original post but I added it. I should have tested but you didn't supply data. See the link in my answer. The SAS users guide should be consulted early and often. – data _null_ Jan 06 '17 at 13:44