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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

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.

 

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
  • 1 reply
  • 696 views
  • 0 likes
  • 2 in conversation