Created
October 19, 2015 16:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*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