DATA Step, Macro, Functions and more

creating a unintialised variable

Accepted Solution Solved
Reply
Occasional Contributor mj5
Occasional Contributor
Posts: 18
Accepted Solution

creating a unintialised variable

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.

Attachment

Accepted Solutions
Solution
‎12-04-2017 04:39 AM
Super User
Super User
Posts: 9,193

Re: creating a unintialised variable

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


All Replies
Solution
‎12-04-2017 04:39 AM
Super User
Super User
Posts: 9,193

Re: creating a unintialised variable

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 102 views
  • 0 likes
  • 2 in conversation