Skip to content

Instantly share code, notes, and snippets.

@josephlei
Created October 19, 2015 16:19
Show Gist options
  • Save josephlei/4980f63bd14e6303738b to your computer and use it in GitHub Desktop.
Save josephlei/4980f63bd14e6303738b to your computer and use it in GitHub Desktop.
SAS MACRO DEFINITION TO UPCASE ALL CHARACTER VARIABLES IN A SPECIFIED DATA SET
*MODIFY THESE GLOBAL OPTIONS AS NEEDED FOR DEBUGGING;
OPTIONS NOMLOGIC NOSYMBOLGEN NOMPRINT;
/***************************************************
CALL/INVOKE MACRO AFTER COMPILATION AS SHOWN HERE;
SYNTAX: %UPCASEALL(LIBRARY_REFERENCE, DATASET_NAME);
EXAMPLE: %UPCASEALL(WORK,_PRODSAVAIL);
***************************************************/
%macro upcaseall(LIBRARY, DATASET);
proc sql;
*COUNT TARGETS;
select count(name) into :charvarcount from sashelp.vcolumn
where libname="&LIBRARY"
and xtype="char"
and memname="&DATASET";
*CREATE TARGETS;
select name into :charvar1-:charvar%left(&charvarcount)
from sashelp.vcolumn
where libname="&LIBRARY"
and xtype="char"
and memname="&DATASET";
quit;
*PROCESS TARGETS;
%do i=1 %to &charvarcount;
DATA &LIBRARY..&DATASET;
SET &LIBRARY..&DATASET;
&&CHARVAR&I=UPCASE(&&CHARVAR&I);
RUN;
%end;
%mend;
%upcaseall(WORK,_PRODSAVAIL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment