<?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 Re: how to write macro for a variable_metadata sheet ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771063#M244627</link>
    <description>&lt;P&gt;Thanks for the response but when i used that code for my DM metadata sheet, it is showing the following NOTE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;NOTE: %INCLUDE (level 1) file codegen is file /saswork/SAS_work7ECC0001CB6C_odaws04-usw2.oda.sas.com/#LN00195.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;NOTE: %INCLUDE (level 1) ending.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable STUDYID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable DOMAIN is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable USUBJID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable SUBJID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFSTDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFENDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFXSTDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFXENDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFICDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFPENDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable DTHDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable DTHFL is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable SITEID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable BRTHDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable AGE is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable AGEU is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable SEX is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RACE is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ARMCD is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ARM is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ACTARMCD is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ACTARM is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable COUNTRY is uninitialized.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Sep 2021 04:55:53 GMT</pubDate>
    <dc:creator>u52766097</dc:creator>
    <dc:date>2021-09-29T04:55:53Z</dc:date>
    <item>
      <title>how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770773#M244512</link>
      <description>&lt;P&gt;how will i do this =&amp;gt; from the spec sheet/metadata file and&amp;nbsp; all attributes from it and&lt;BR /&gt;then at run time assign the attributes in each program using a macro.&lt;BR /&gt;proc import -&amp;gt; subset for a dataset -&amp;gt; create attrib statement from that dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 02:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770773#M244512</guid>
      <dc:creator>u52766097</dc:creator>
      <dc:date>2021-09-28T02:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770820#M244523</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364694"&gt;@u52766097&lt;/a&gt;&amp;nbsp;Pretty much along the line how you describe it. I guess you ask because you're not sure how to do below bit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is self-contained and you can run it by copy/pasting into your environment.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dd;
  infile datalines4 dsd dlm=',' truncover;
  input name :$32. type :$4. length :$5. format :$32. informat :$32. label :$256.;
  datalines4;
colA,char,20,
colB,num,8,datetime21.,,Column B
;;;;

filename codegen temp;
data _null_;
  file codegen;
  set dd;
  put 'attrib ' name @;
  if type='char' then put 'length=$' length @;
  else put 'length=' length @;
  if not missing(format) then put 'format=' format @;
  if not missing(informat) then put 'informat=' informat @;
  /* with labels eventually a bit more logic required in case you need to expect quotes */
  /* and/or macro tokens liek &amp;amp; in the text */
  if not missing(label) then put 'label="' label +(-1) '"' @;
  put ';';
run;

data want;
  %include codegen /source2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need more elaborate code then get yourself inspired by &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;Jedi SAS Tricks: The DATA to DATA Step Macro&lt;/A&gt;&amp;nbsp;and the macro linked at the end of the blog.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 08:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770820#M244523</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-28T08:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770889#M244542</link>
      <description>&lt;P&gt;No extra logic needed for LABEL attribute. Use the $QUOTE format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if you name your metadata fields to match the ATTRIB keyword then you can have SAS automatically write the keyword.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not missing(format) then put format= @;
if not missing(informat) then put informat= @;
if not missing(label) then put label= :$quote. @;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 13:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770889#M244542</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-28T13:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770925#M244558</link>
      <description>&lt;P&gt;I tried this method for creating the macro for variables ,so how will i use this for a dataset with attribe statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro adsl;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select memname into:names separated by '|'&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname eq 'RAW' and memname not in ('DEFINE');&lt;BR /&gt;quit;&lt;BR /&gt;%put &amp;amp;names;&lt;BR /&gt;%let i=1;&lt;BR /&gt;%do %while(%scan(&amp;amp;names,&amp;amp;i,|) ne );&lt;BR /&gt;%put **********************;&lt;BR /&gt;%put **********************;&lt;BR /&gt;%put * ;&lt;BR /&gt;%put * %scan(&amp;amp;names,&amp;amp;i,|);&lt;BR /&gt;%put * ;&lt;BR /&gt;%put **********************;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select domain into:dslabel&lt;BR /&gt;from rawdata.define&lt;BR /&gt;where domain eq "%scan(&amp;amp;names,&amp;amp;i,|)";&lt;BR /&gt;select compress(put(count(*),8.)) into:cn&lt;BR /&gt;from rawdata.define&lt;BR /&gt;where domain eq "%scan(&amp;amp;names,&amp;amp;i,|)";&lt;/P&gt;&lt;P&gt;select variable, label, length&lt;BR /&gt;into:column1 - :column&amp;amp;cn,&lt;BR /&gt;:label1 - :label&amp;amp;cn,&lt;BR /&gt;:vform1 - :vform&amp;amp;cn&lt;BR /&gt;from rawdata.define&lt;BR /&gt;where domain eq "%scan(&amp;amp;names,&amp;amp;i,|)";&lt;BR /&gt;quit;&lt;BR /&gt;data derdata.%scan(&amp;amp;names,&amp;amp;i,|) (label="&amp;amp;dslabel" );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set RAW.%scan(&amp;amp;names,&amp;amp;i,|);&lt;BR /&gt;%do j=1 %to &amp;amp;cn;&lt;BR /&gt;label &amp;amp;&amp;amp;&amp;amp;column&amp;amp;j ="&amp;amp;&amp;amp;&amp;amp;label&amp;amp;j";&lt;BR /&gt;format &amp;amp;&amp;amp;&amp;amp;column&amp;amp;j &amp;amp;&amp;amp;&amp;amp;vform&amp;amp;j..;&lt;BR /&gt;%end;&lt;BR /&gt;run;&lt;BR /&gt;%let i=%eval(&amp;amp;i+1);&lt;BR /&gt;%end;&lt;BR /&gt;%mend adsl;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 15:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770925#M244558</guid>
      <dc:creator>u52766097</dc:creator>
      <dc:date>2021-09-28T15:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770997#M244596</link>
      <description>&lt;P&gt;I never see much value in taking data out of a dataset into macro variables like that.&amp;nbsp; Just use the method that writes the code to a file. Much easier to understand, read, write and debug.&amp;nbsp; No messing around with converting number to strings to store into macro variables, no need to use macro logic, worry about macro quoting etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you putting values from the &lt;STRONG&gt;LENGTH&lt;/STRONG&gt; variable of&amp;nbsp;&lt;STRONG&gt;rawdata.define&lt;/STRONG&gt;&amp;nbsp; into macro variables named VFORM....?&lt;/P&gt;
&lt;P&gt;And then why are you using those LENGTH values to generate the FORMAT attribute for the variables?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are confusing the defined LENGTH of a variable (how much space it takes to store the variable in the dataset) and the display format attached to the variable (how you want the value to display by default).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also don't seem to be pulling any TYPE information out that metadata table.&amp;nbsp; Do you only have one type of variable? If so are they floating point numbers or fixed length character strings.&amp;nbsp; Those are the only two choices for SAS variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about variables that actually need to have formats attached to them (for example DATE, TIME and DATETIME values) to make them user readable? How do you propose attaching a proper format to those?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Sep 2021 20:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/770997#M244596</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-28T20:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771063#M244627</link>
      <description>&lt;P&gt;Thanks for the response but when i used that code for my DM metadata sheet, it is showing the following NOTE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;NOTE: %INCLUDE (level 1) file codegen is file /saswork/SAS_work7ECC0001CB6C_odaws04-usw2.oda.sas.com/#LN00195.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;NOTE: %INCLUDE (level 1) ending.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable STUDYID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable DOMAIN is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable USUBJID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable SUBJID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFSTDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFENDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFXSTDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFXENDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFICDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RFPENDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable DTHDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable DTHFL is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable SITEID is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable BRTHDTC is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable AGE is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable AGEU is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable SEX is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable RACE is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ARMCD is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ARM is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ACTARMCD is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable ACTARM is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable COUNTRY is uninitialized.&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 04:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771063#M244627</guid>
      <dc:creator>u52766097</dc:creator>
      <dc:date>2021-09-29T04:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771064#M244628</link>
      <description>&lt;P&gt;If you ran code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  attrib var1 length=$10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then those are expected messages.&lt;/P&gt;
&lt;P&gt;What is the source for the actual data?&amp;nbsp; Do you have some existing dataset?&amp;nbsp; Are you reading from some text file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no data then add a STOP statement to insure that no observations are written.&lt;/P&gt;
&lt;P&gt;You could use CALL MISSING() to prevent the uninitialized messages.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  %include codegen /source2;
  call missing(of _all_);
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Sep 2021 05:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771064#M244628</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-29T05:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to write macro for a variable_metadata sheet ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771471#M244826</link>
      <description>&lt;P&gt;thanks for reply, it worked .&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 19:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-macro-for-a-variable-metadata-sheet/m-p/771471#M244826</guid>
      <dc:creator>u52766097</dc:creator>
      <dc:date>2021-09-30T19:15:28Z</dc:date>
    </item>
  </channel>
</rss>

