<?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 efficiently manage large set of value format labels, and only apply them when in the data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356060#M274074</link>
    <description>&lt;P&gt;Make the dataset without formats, then run a macro calling dictionary.columns to get all the varnames and make a macrovar listing the varnames and matching format names. Then run PROC DATASETS to assign the formats, using that macrovar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input a b c;
datalines;
1 11 111
run;

proc format;
  value a other=[3.];
  value b other=[3.];
  value c other=[3.];
  value x other=[3.];
  value y other=[3.];
run;

%macro assign_fmts(dsn);
   %let dsn=%upcase(&amp;amp;dsn);
   %let dataset=%scan(&amp;amp;dsn,-1,%str(.));
   %if &amp;amp;dataset=&amp;amp;dsn %then %let libname=WORK;
   %else %let libname=%upcase(%scan(&amp;amp;dsn,1,%str(.)));
   %put _local_;
   proc sql noprint;
     select distinct catx(' ',name,cats(name,.)) into :fmts separated by " "
       from dictionary.columns where libname="&amp;amp;libname" and memname="&amp;amp;dataset";
   quit;
   proc datasets lib=&amp;amp;libname noprint ;
      modify &amp;amp;dataset;
      format &amp;amp;fmts;
      run;
   quit;
%mend ;

%assign_fmts(test);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2017 18:01:24 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-05-04T18:01:24Z</dc:date>
    <item>
      <title>How to efficiently manage large set of value format labels, and only apply them when in the dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355830#M274069</link>
      <description>&lt;P&gt;I have a .sas file with proc format for 200 variables (let's call it FORMATS.sas).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, when I read in actual data from an INFILE statement (let's call this DATAFILE), I %include the FORMATS.sas file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, in the data step I have a format statement which then lists all 200 variable names and their format labels, so imagine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;format &amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&amp;nbsp; &amp;nbsp;var1 var1.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&amp;nbsp; &amp;nbsp;var2 var2.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&amp;nbsp; &amp;nbsp;var3 var3.&amp;nbsp;; &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="blue"&gt;&lt;FONT color="black"&gt;(...etc until all 200 are listed).&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 2 issues with this process:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. If I&amp;nbsp;choose&amp;nbsp;to only read in 10 of the 200 variables in the INFILE, the&amp;nbsp;FORMAT statement will give 190 errors. So how can I only&amp;nbsp;apply formats to variables that actually have been read in (without manually commenting out 190 lines in the format statement)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. How can I make this more efficient in general? I would like it to just have a database that it automatically grabs the format labels since&amp;nbsp;the variable and its corresponding format is exactly the same name?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 02:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355830#M274069</guid>
      <dc:creator>fieldsa83</dc:creator>
      <dc:date>2017-05-04T02:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355836#M274070</link>
      <description>&lt;P&gt;I would just assign the formats to the entire file and save the file with the formats attached. Isn't that possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Conversely, if that isn't possible, then I'd create a&amp;nbsp;macro in which you could specify the desired variable, use proc sql to read all of the variables from dictionary.columns, have it write a macro variable that included all of the desired format assignments, and then apply them while selecting the desired file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 03:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355836#M274070</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-04T03:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355837#M274071</link>
      <description>&lt;P&gt;The dictionary.column macro sounds intriguing. Do you have a sample code of how that would work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(the first option isn't possible since the source data is actually in non-writeable text files, and there are&amp;nbsp;hundreds of gigabytes worth--so I don't want to make 1 single database. also new text files are added each month to the folder)&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 03:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355837#M274071</guid>
      <dc:creator>fieldsa83</dc:creator>
      <dc:date>2017-05-04T03:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355844#M274072</link>
      <description>&lt;P&gt;Since they're text files you would need to be able to read in all variables. As such, you would need to know the file layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you kept the variable names, location, informats and relevant formats if any for all variables, then that file could be accessed and, using statements in sql like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select catx(' ','input ',varname,column_range,informat,'@;',&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catx(' ',format,varname,format),&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; etc. into : inputs separated by ' ', formats separated by ' '&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where varname in &amp;amp;macro_variable_listing_all_desired_variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;those macro variables could be used to both input and format the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 04:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/355844#M274072</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-04T04:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356060#M274074</link>
      <description>&lt;P&gt;Make the dataset without formats, then run a macro calling dictionary.columns to get all the varnames and make a macrovar listing the varnames and matching format names. Then run PROC DATASETS to assign the formats, using that macrovar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input a b c;
datalines;
1 11 111
run;

proc format;
  value a other=[3.];
  value b other=[3.];
  value c other=[3.];
  value x other=[3.];
  value y other=[3.];
run;

%macro assign_fmts(dsn);
   %let dsn=%upcase(&amp;amp;dsn);
   %let dataset=%scan(&amp;amp;dsn,-1,%str(.));
   %if &amp;amp;dataset=&amp;amp;dsn %then %let libname=WORK;
   %else %let libname=%upcase(%scan(&amp;amp;dsn,1,%str(.)));
   %put _local_;
   proc sql noprint;
     select distinct catx(' ',name,cats(name,.)) into :fmts separated by " "
       from dictionary.columns where libname="&amp;amp;libname" and memname="&amp;amp;dataset";
   quit;
   proc datasets lib=&amp;amp;libname noprint ;
      modify &amp;amp;dataset;
      format &amp;amp;fmts;
      run;
   quit;
%mend ;

%assign_fmts(test);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 18:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356060#M274074</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-04T18:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356352#M274075</link>
      <description>&lt;P&gt;This is perfect, thanks so much! Really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One thing: it seems to break if the varname has an underscore in it, do you think there's a way to solve that (not a big deal if not)?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 13:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356352#M274075</guid>
      <dc:creator>fieldsa83</dc:creator>
      <dc:date>2017-05-05T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356428#M274076</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98628"&gt;@fieldsa83&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;This is perfect, thanks so much! Really appreciate it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing: it seems to break if the varname has an underscore in it, do you think there's a way to solve that (not a big deal if not)?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should provide an example of the variable name and the format you are want to assign and describe any symptoms in more detail than "seems to break". if you get errors post the log with the errors. Since a macro may be involved run the code with&lt;/P&gt;
&lt;P&gt;OPTIONS MPRINT SYMBOLGEN;&lt;/P&gt;
&lt;P&gt;to get more detail into the log.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 15:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356428#M274076</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-05T15:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356536#M274077</link>
      <description>&lt;P&gt;Sorry I don't think the underscore is actually a problem as much as I am confused...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i add a suffix to the variable format name? I'm trying to add "en" to the end of every variable name format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to add it in the same section as the period but it's&amp;nbsp;saying "the following columns were not found in the contribitng tables: en"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And if i try to add _en it says "syntax error, expecting one of the following: a name, *."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally the result would be varname1 varname1_en.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 20:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356536#M274077</guid>
      <dc:creator>fieldsa83</dc:creator>
      <dc:date>2017-05-05T20:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356548#M274078</link>
      <description>&lt;P&gt;Then instead of&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;,'en',&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Study the CATS function, and the related CATX, etc.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 21:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356548#M274078</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-05T21:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to efficiently manage large set of value format labels, and only apply them when in the data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356556#M274079</link>
      <description>&lt;P&gt;Thanks. I'm very interested in how I would&amp;nbsp;use this to input variables, as you say.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If for example my text file has AGE at&amp;nbsp;line 10 for 3 characters, how would I incorporate that in this?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 21:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-efficiently-manage-large-set-of-value-format-labels-and/m-p/356556#M274079</guid>
      <dc:creator>fieldsa83</dc:creator>
      <dc:date>2017-05-05T21:24:34Z</dc:date>
    </item>
  </channel>
</rss>

