I am using the below code and somehow it creates UUSUBJID_USE which is not available and gets unintialised variable. Not sure from where it is creating. can any one help me to debug it.
%macro inhc; %let LstCols = %quote(USUBJID SEX AGE RACE WEIGHTBL); %let totval=%eval(%sysfunc(countc(&LstCols,%str( )))+1); %let LstCols_u=%sysfunc(tranwrd(&LstCols,SUBJID,USUBJID_USE)); %let LstCols_use=%sysfunc(tranwrd(&LstCols_u.,RACE,RACE_USE)); data inc; set adam.adsl; %do i=1 %to &totval; %if %upcase(%scan(&LstCols_use,&i)) eq %upcase(actarm) %then %do; patinf=catx("/",patinf,actarm); if _n_=1 then patlbl=catx("/",patlbl,"treatment"); %end; %else %do; patinf=catx("/",patinf,(%scan(&LstCols_use,&i))); if _n_=1 then patlbl=catx("/",patlbl,vlabel(%scan(&LstCols,&i))); %end; %end; run; %mend; %inhc;
attaching test data.
Log:
UUSUBJID_USE=. patlbl=. RACE_USE=. _ERROR_=1 _N_=19
NOTE: Over 100 NOTES, additional NOTES suppressed.
NOTE: Invalid numeric data, './.' , at line 3 column 25.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
Same old, same old. These types of questions get asked daily. First off, why are you doing this in macro at all? Macro does not do anything other some text replace function. That mass of unwieldy code resolves to one simply datastep;
data inc; set adam.adsl; array v{5} usubjid sex race age weightbl; do i=1 to 5; if vvname(v{i})="actarm" then do; ...; end; else do; ..; end; end; run;
As for why the text generated is UUSUBJID_USE, well look at:
%let LstCols = %quote(USUBJID SEX AGE RACE WEIGHTBL);
And:
%let LstCols_u=%sysfunc(tranwrd(&LstCols,SUBJID,USUBJID_USE));
So when you replace U<SUBJID> with USUBJID_USE, you get UUSUBJID_USE.
Same old, same old. These types of questions get asked daily. First off, why are you doing this in macro at all? Macro does not do anything other some text replace function. That mass of unwieldy code resolves to one simply datastep;
data inc; set adam.adsl; array v{5} usubjid sex race age weightbl; do i=1 to 5; if vvname(v{i})="actarm" then do; ...; end; else do; ..; end; end; run;
As for why the text generated is UUSUBJID_USE, well look at:
%let LstCols = %quote(USUBJID SEX AGE RACE WEIGHTBL);
And:
%let LstCols_u=%sysfunc(tranwrd(&LstCols,SUBJID,USUBJID_USE));
So when you replace U<SUBJID> with USUBJID_USE, you get UUSUBJID_USE.
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.