Unable to call macro loadcpddata in macro loading:
data cpdlogic (sortedby=CPDCOBRS_VAR_NM CPDCOBRS_GRP_T);
set loaddata.cpdlogic;
if CPDCOBRS_CATG_T='CPD_logic' then do;
FieldCounterChar = left(put(_n_,6.));
FieldCounter = _n_;
output;
end;
run;
proc sql noprint;
select max(FieldCounter) into :TotalFieldCount
from cpdlogic ;
quit;
%put &TotalFieldCount;
%macro LoadCPDData (Group,Field_Num);
proc sql noprint;
select CPDCOBRS_VAR_NM into :FieldName
from cpdlogic
where CPDCOBRS_GRP_T=&Group
and FieldCounter=&Field_Num;
quit;
%put [&Field_Num];
%global &FieldName;
proc sql noprint;
select CPDCOBRS_RTRN_VLU_1 into :&FieldName
from cpdlogic
where CPDCOBRS_GRP_T=&Group;
quit;
%mend LoadCPDData;
%macro loading;
%if &TotalFieldCount > 1 %then %do;
%do i=1 %to &TotalFieldCount;
%LoadCPDData(&cpd,&i);
%end;
%end;
%mend loading;
DATA:
CPDCOBRS_CATG_T | CPDCOBRS_GRP_T | CPDCOBRS_VAR_NM | CPDCOBRS_RTRN_VLU_1 |
CPD_logic | 4 | DeanOrnish_paper_practvend | Y |
CPD_logic | 6 | DeanOrnish_paper_practvend | Y |
CPD_logic | 19 | DeanOrnish_paper_practvend | Y |
CPD_logic | 47 | DeanOrnish_paper_practvend | Y |
CPD_logic | 85 | DeanOrnish_paper_practvend | Y |
CPD_logic | 95 | DeanOrnish_paper_practvend | Y |
You're not very specific about what happens when you try to run this. However, here's an issue that stands out.
For %LoadCPDData(&cpd,&i) to work, there must be an existing macro variable named CPD. I don't see how your program creates that.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.