<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic problem about how to use macro to modify all character variables of datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170144#M32678</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I recently read a paper "A Macro to Modify Attributes for All Character Variables in SAS". But&amp;nbsp; it seems that the macro provided could only deal with blanks. what I really want to do is to compress characters like"-,.,,@,$" in observations.&lt;/P&gt;&lt;P&gt;The macro is posted below. Anyone could tell me how to revise the macro so that I can&amp;nbsp; compress those characters? Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*****PART1;&lt;/P&gt;&lt;P&gt;%macro Modify_All_Character_Variables;&lt;BR /&gt;%let ExitVariable=1;&lt;BR /&gt;/*checking whether or not required input parameters are defined*/&lt;BR /&gt;%if %length(&amp;amp;datasets)&amp;gt;0 and %upcase(&amp;amp;datasets)^= and %length(&amp;amp;function_name)&amp;gt;0 and&lt;BR /&gt;%upcase(&amp;amp;function_name)^=&lt;BR /&gt;%then %let ExitVariable=0;&lt;BR /&gt;%if %eval(&amp;amp;ExitVariable)&amp;gt;0 %then %do;&lt;BR /&gt;%put;%put !!! Not enough parameters defined to run this macro !!!;%put;&lt;BR /&gt;%goto LastExit;&lt;BR /&gt;%end;&lt;BR /&gt;/*checking whether or not input "function_name" parameter is valid*/&lt;BR /&gt;%if %length(%sysfunc(&amp;amp;function_name(TEST)))&amp;lt;4 %then %do;&lt;BR /&gt;%put; %put !!! Please provide valid SAS character function name !!!;%put;&lt;BR /&gt;%goto LastExit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*This portion of the code checks whether or not the user has provided both of the required inputs by using the&lt;BR /&gt;%SYSFUNC and %LENGTH functions. The “ExitVariable” macro variable acts as an ON/OFF switch with a default&lt;BR /&gt;value of '1' (OFF condition). Only when both input parameters are defined does its value get reset to '0' and the&lt;BR /&gt;macro proceeds further. If any of the two parameters are not defined, an error message will be displayed in the log&lt;BR /&gt;window. The second check validates the applicability of the user-defined SAS function by testing the changes to the&lt;BR /&gt;length of the word “TEST”. Failure of either check diverts the code to go to the “LastExit” statement at the end of the&lt;BR /&gt;macro.*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*****PART2;&lt;/P&gt;&lt;P&gt;options nonotes;&lt;BR /&gt;/*counting the number of submitted datasets*/&lt;BR /&gt;data _NULL_; call symput('DSNo',count("&amp;amp;datasets",' ')+1); run;&lt;BR /&gt;%do D=1 %to &amp;amp;DSNo;&lt;BR /&gt;%let sel_dataset=%scan(&amp;amp;datasets,&amp;amp;D,' ');&lt;BR /&gt;%put;&lt;BR /&gt;%put Applying "&amp;amp;function_name" function to the dataset: &amp;amp;sel_dataset;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;sel_dataset))=0 %then %do;&lt;BR /&gt;%put !!! "&amp;amp;sel_dataset" does not exist. Please check. !!!; %put;&lt;BR /&gt;%goto Exit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*This portion of code counts the number of “space” characters in the user-defined “datasets” parameter. The best&lt;BR /&gt;method to count “useful” spaces is to use the CALL SYMPUT function inside a DATA _NULL_ step. Then a %DO&lt;BR /&gt;loop is set with the limit of as many datasets as needed to process. Within the %DO loop, “sel_dataset” names are&lt;BR /&gt;assigned sequentially, and the presence of the respective SAS table is also checked using and EXIST functions.*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;********PART3;&lt;/P&gt;&lt;P&gt;/*identifying the character variables from the SAS data table*/&lt;BR /&gt;proc contents data=&amp;amp;sel_dataset out=Tmp noprint; run;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;%let sel_Cvariables=; %let sel_Nvariables=;&lt;BR /&gt;select compress(left(NAME)),&lt;BR /&gt;catt(compress(left(NAME)),"=&amp;amp;function_name(",compress(left(NAME)),')')&lt;BR /&gt;into:sel_Cvariables separated by ', ',:sel_Nvariables separated by ', ' from Tmp where&lt;BR /&gt;Type=2;&lt;/P&gt;&lt;P&gt;drop table Tmp;&lt;BR /&gt;%if %length(&amp;amp;sel_Nvariables)=0 %then %do;&lt;BR /&gt;%put !!! There are no character variables in this dataset !!!;%put;&lt;BR /&gt;%goto Exit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Using PROC CONTENTS, information about character variables within each of the input data tables is generated. If&lt;BR /&gt;there are no character variables in the given dataset, the code is diverted to the “Exit” statement before the loop&lt;BR /&gt;%END statement. In addition, a message is written to the log window regarding this issue. Otherwise, SQL syntax for&lt;BR /&gt;updating character variables with the user-defined SAS function gets generated. This information is stored in SAS&lt;BR /&gt;memory with the help of the “sel_Nvariable” macro variable.*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;**********PART4;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*applying the character function specified by the user*/&lt;BR /&gt;update &amp;amp;sel_dataset set &amp;amp;sel_Nvariables;&lt;BR /&gt;quit;&lt;BR /&gt;%put "&amp;amp;function_name" converted variables: &amp;amp;sel_Cvariables;&lt;BR /&gt;%Exit : ;&lt;BR /&gt;%let sel_dataset=; %let Sel_cvariables=; %let Sel_nvariables=;&lt;BR /&gt;%put;&lt;BR /&gt;%end;&lt;BR /&gt;%put;%put !!! Done. Thanks for using "Modify_All_Character_Variables" macro !!!;%put;&lt;BR /&gt;%LastExit: ;&lt;BR /&gt;%symdel datasets function_name;&lt;BR /&gt;option notes;&lt;BR /&gt;%mend ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Dec 2013 16:23:31 GMT</pubDate>
    <dc:creator>owenwqp1</dc:creator>
    <dc:date>2013-12-11T16:23:31Z</dc:date>
    <item>
      <title>problem about how to use macro to modify all character variables of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170144#M32678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I recently read a paper "A Macro to Modify Attributes for All Character Variables in SAS". But&amp;nbsp; it seems that the macro provided could only deal with blanks. what I really want to do is to compress characters like"-,.,,@,$" in observations.&lt;/P&gt;&lt;P&gt;The macro is posted below. Anyone could tell me how to revise the macro so that I can&amp;nbsp; compress those characters? Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*****PART1;&lt;/P&gt;&lt;P&gt;%macro Modify_All_Character_Variables;&lt;BR /&gt;%let ExitVariable=1;&lt;BR /&gt;/*checking whether or not required input parameters are defined*/&lt;BR /&gt;%if %length(&amp;amp;datasets)&amp;gt;0 and %upcase(&amp;amp;datasets)^= and %length(&amp;amp;function_name)&amp;gt;0 and&lt;BR /&gt;%upcase(&amp;amp;function_name)^=&lt;BR /&gt;%then %let ExitVariable=0;&lt;BR /&gt;%if %eval(&amp;amp;ExitVariable)&amp;gt;0 %then %do;&lt;BR /&gt;%put;%put !!! Not enough parameters defined to run this macro !!!;%put;&lt;BR /&gt;%goto LastExit;&lt;BR /&gt;%end;&lt;BR /&gt;/*checking whether or not input "function_name" parameter is valid*/&lt;BR /&gt;%if %length(%sysfunc(&amp;amp;function_name(TEST)))&amp;lt;4 %then %do;&lt;BR /&gt;%put; %put !!! Please provide valid SAS character function name !!!;%put;&lt;BR /&gt;%goto LastExit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*This portion of the code checks whether or not the user has provided both of the required inputs by using the&lt;BR /&gt;%SYSFUNC and %LENGTH functions. The “ExitVariable” macro variable acts as an ON/OFF switch with a default&lt;BR /&gt;value of '1' (OFF condition). Only when both input parameters are defined does its value get reset to '0' and the&lt;BR /&gt;macro proceeds further. If any of the two parameters are not defined, an error message will be displayed in the log&lt;BR /&gt;window. The second check validates the applicability of the user-defined SAS function by testing the changes to the&lt;BR /&gt;length of the word “TEST”. Failure of either check diverts the code to go to the “LastExit” statement at the end of the&lt;BR /&gt;macro.*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*****PART2;&lt;/P&gt;&lt;P&gt;options nonotes;&lt;BR /&gt;/*counting the number of submitted datasets*/&lt;BR /&gt;data _NULL_; call symput('DSNo',count("&amp;amp;datasets",' ')+1); run;&lt;BR /&gt;%do D=1 %to &amp;amp;DSNo;&lt;BR /&gt;%let sel_dataset=%scan(&amp;amp;datasets,&amp;amp;D,' ');&lt;BR /&gt;%put;&lt;BR /&gt;%put Applying "&amp;amp;function_name" function to the dataset: &amp;amp;sel_dataset;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;sel_dataset))=0 %then %do;&lt;BR /&gt;%put !!! "&amp;amp;sel_dataset" does not exist. Please check. !!!; %put;&lt;BR /&gt;%goto Exit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*This portion of code counts the number of “space” characters in the user-defined “datasets” parameter. The best&lt;BR /&gt;method to count “useful” spaces is to use the CALL SYMPUT function inside a DATA _NULL_ step. Then a %DO&lt;BR /&gt;loop is set with the limit of as many datasets as needed to process. Within the %DO loop, “sel_dataset” names are&lt;BR /&gt;assigned sequentially, and the presence of the respective SAS table is also checked using and EXIST functions.*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;********PART3;&lt;/P&gt;&lt;P&gt;/*identifying the character variables from the SAS data table*/&lt;BR /&gt;proc contents data=&amp;amp;sel_dataset out=Tmp noprint; run;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;%let sel_Cvariables=; %let sel_Nvariables=;&lt;BR /&gt;select compress(left(NAME)),&lt;BR /&gt;catt(compress(left(NAME)),"=&amp;amp;function_name(",compress(left(NAME)),')')&lt;BR /&gt;into:sel_Cvariables separated by ', ',:sel_Nvariables separated by ', ' from Tmp where&lt;BR /&gt;Type=2;&lt;/P&gt;&lt;P&gt;drop table Tmp;&lt;BR /&gt;%if %length(&amp;amp;sel_Nvariables)=0 %then %do;&lt;BR /&gt;%put !!! There are no character variables in this dataset !!!;%put;&lt;BR /&gt;%goto Exit;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Using PROC CONTENTS, information about character variables within each of the input data tables is generated. If&lt;BR /&gt;there are no character variables in the given dataset, the code is diverted to the “Exit” statement before the loop&lt;BR /&gt;%END statement. In addition, a message is written to the log window regarding this issue. Otherwise, SQL syntax for&lt;BR /&gt;updating character variables with the user-defined SAS function gets generated. This information is stored in SAS&lt;BR /&gt;memory with the help of the “sel_Nvariable” macro variable.*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;**********PART4;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*applying the character function specified by the user*/&lt;BR /&gt;update &amp;amp;sel_dataset set &amp;amp;sel_Nvariables;&lt;BR /&gt;quit;&lt;BR /&gt;%put "&amp;amp;function_name" converted variables: &amp;amp;sel_Cvariables;&lt;BR /&gt;%Exit : ;&lt;BR /&gt;%let sel_dataset=; %let Sel_cvariables=; %let Sel_nvariables=;&lt;BR /&gt;%put;&lt;BR /&gt;%end;&lt;BR /&gt;%put;%put !!! Done. Thanks for using "Modify_All_Character_Variables" macro !!!;%put;&lt;BR /&gt;%LastExit: ;&lt;BR /&gt;%symdel datasets function_name;&lt;BR /&gt;option notes;&lt;BR /&gt;%mend ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 16:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170144#M32678</guid>
      <dc:creator>owenwqp1</dc:creator>
      <dc:date>2013-12-11T16:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: problem about how to use macro to modify all character variables of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170145#M32679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't need a macro IMO&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array all(*) _character_;&lt;/P&gt;&lt;P&gt;do i=1 to dim(all);&lt;/P&gt;&lt;P&gt;all(i)=compress(all(i), &amp;lt;*insert proper functions here*&amp;gt;);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Dec 2013 16:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170145#M32679</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-12-11T16:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: problem about how to use macro to modify all character variables of datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170146#M32680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;n wrote:&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I recently read a paper "A Macro to Modify Attributes for All Character Variables in SAS". But&amp;nbsp; it seems that the macro provided could only deal with blanks. what I really want to do is to compress characters like"-,.,,@,$" in observations.&lt;/P&gt;
&lt;P&gt;The macro is posted below. Anyone could tell me how to revise the macro so that I can&amp;nbsp; compress those characters? Thanks!&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;select compress(left(NAME)),&lt;BR /&gt;catt(compress(left(NAME)),"=&amp;amp;function_name(",compress(left(NAME)),')'&lt;/P&gt;
&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P style="display: inline !important;"&gt;&lt;/P&gt;


&lt;/PRE&gt;


&lt;/PRE&gt;&lt;P&gt;Given that&lt;/P&gt;&lt;P&gt;Result = compress( source, 'abcdefgijklmnopqrstuvwxyz', 'ki' );&lt;/P&gt;&lt;P&gt;keeps only upper and lowercase letters in the source variable without fully understanding the macro, I assume you want to have some impact on the functionality of the macro that I do not understand.&lt;/P&gt;&lt;P&gt;I would recommend you contact the author of the paper/macro to see if the functionality you seek can be achieved.&lt;/P&gt;&lt;P&gt;Who was the author?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;peterC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Dec 2013 07:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-about-how-to-use-macro-to-modify-all-character-variables/m-p/170146#M32680</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-12-18T07:30:25Z</dc:date>
    </item>
  </channel>
</rss>

