<?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 Retrieving variables' labels, formats and type within a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retrieving-variables-labels-formats-and-type-within-a-macro/m-p/581304#M165206</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to adjust a macro - here called MacroBL -, which was developed by someone else. For this macro to function, I need to write the variables that I want and separate them with an backslash (\). For each variable I need to write the name, type (CTN: continuous, or CTG: categorical) and label manually. There is no way for this macro to retrieve the variable's format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have tried to do for the last six hours is to let the macro recognize the variable's label, format and type directly as present in the data. I tried several methods like using&amp;nbsp;vlabelx,&amp;nbsp;varlabel or&amp;nbsp;%sysfunc(varlabel) but I didn't get it to work.&lt;/P&gt;&lt;P&gt;I am not a macro expert and the answer should be really easy. Do you guys have an idea?&amp;nbsp; Thanks in forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the essential part of the macro I'm trying to manipulate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MacroBL(data=, var=var1|CTN|label1\ var2|CTG|label2)&lt;BR /&gt;&lt;BR /&gt;%let nvar=%sysfunc(countw(&amp;amp;var,%str(\)));

%do n=1 %to &amp;amp;nvar;	
	%let var&amp;amp;n=%scan(%qscan(&amp;amp;var,&amp;amp;n,%str(\)),1,|);
	%let vartype&amp;amp;n=%scan(%qscan(&amp;amp;var,&amp;amp;n,%str(\)),2,|);
	%let varlabel&amp;amp;n=%scan(%qscan(&amp;amp;var,&amp;amp;n,%str(\)),3,|);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Aug 2019 22:44:56 GMT</pubDate>
    <dc:creator>Ubai</dc:creator>
    <dc:date>2019-08-14T22:44:56Z</dc:date>
    <item>
      <title>Retrieving variables' labels, formats and type within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieving-variables-labels-formats-and-type-within-a-macro/m-p/581304#M165206</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to adjust a macro - here called MacroBL -, which was developed by someone else. For this macro to function, I need to write the variables that I want and separate them with an backslash (\). For each variable I need to write the name, type (CTN: continuous, or CTG: categorical) and label manually. There is no way for this macro to retrieve the variable's format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have tried to do for the last six hours is to let the macro recognize the variable's label, format and type directly as present in the data. I tried several methods like using&amp;nbsp;vlabelx,&amp;nbsp;varlabel or&amp;nbsp;%sysfunc(varlabel) but I didn't get it to work.&lt;/P&gt;&lt;P&gt;I am not a macro expert and the answer should be really easy. Do you guys have an idea?&amp;nbsp; Thanks in forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the essential part of the macro I'm trying to manipulate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MacroBL(data=, var=var1|CTN|label1\ var2|CTG|label2)&lt;BR /&gt;&lt;BR /&gt;%let nvar=%sysfunc(countw(&amp;amp;var,%str(\)));

%do n=1 %to &amp;amp;nvar;	
	%let var&amp;amp;n=%scan(%qscan(&amp;amp;var,&amp;amp;n,%str(\)),1,|);
	%let vartype&amp;amp;n=%scan(%qscan(&amp;amp;var,&amp;amp;n,%str(\)),2,|);
	%let varlabel&amp;amp;n=%scan(%qscan(&amp;amp;var,&amp;amp;n,%str(\)),3,|);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 22:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieving-variables-labels-formats-and-type-within-a-macro/m-p/581304#M165206</guid>
      <dc:creator>Ubai</dc:creator>
      <dc:date>2019-08-14T22:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieving variables' labels, formats and type within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retrieving-variables-labels-formats-and-type-within-a-macro/m-p/581305#M165207</link>
      <description>&lt;P&gt;You can get variable names, labels and formats from Dictionary.columns (or sashelp.vcolumn) given a library and dataset name.&lt;/P&gt;
&lt;P&gt;Or with proc contents. But are you sure every variable has a format assigned? a Label?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And&amp;nbsp;what information in the data set metadata tells you that a variable is categorical or continuous?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code creates a table of properties of the data set SASHELP.BASEBALL.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.properties as 
   select name, type,label,format
   from dictionary.columns
   where libname='SASHELP' and memname='BASEBALL';
quit;&lt;/PRE&gt;
&lt;P&gt;Note the TYPE will be "char" or "num" in the resulting set. I don't know how to get CTN or CTG from these properties for this data set.&lt;/P&gt;
&lt;P&gt;That might be sufficient with a data step using that information to create either an %include file with the call to the macro using that data set information, or Call execute&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 23:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retrieving-variables-labels-formats-and-type-within-a-macro/m-p/581305#M165207</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-14T23:00:21Z</dc:date>
    </item>
  </channel>
</rss>

