<?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 Adding Multiple Values to a Dataset Using PROC FORMAT in Programming 1 and 2</title>
    <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805644#M1054</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4539"&gt;@Sas&lt;/a&gt; Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have a dataset with about 594 variables which I am preparing for analyses. I have added variable labels using the right procedure. To add the corresponding values to few variables, I used PROC FORMAT:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc format; 
	VALUE HNCO1K 1="Very good" 2="Good"; 
	VALUE HTM50L 0="V" 1="G"; 
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;I would like to add the analogous values which I defined, using PROC FORMAT, to each of the 594 variables. Using the data step, I know I could apply the format as such to few variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA help_formatted2;

&amp;nbsp;&amp;nbsp;&amp;nbsp; SET help;

&amp;nbsp;&amp;nbsp;&amp;nbsp; FORMAT Rate HNCO1K. Code HTM50L.;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am struggling to find the most efficient way to add the values to all 594 variables in one attempt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I shall be most grateful for your help.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Apr 2022 22:23:38 GMT</pubDate>
    <dc:creator>Zacc</dc:creator>
    <dc:date>2022-04-02T22:23:38Z</dc:date>
    <item>
      <title>Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805644#M1054</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4539"&gt;@Sas&lt;/a&gt; Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do have a dataset with about 594 variables which I am preparing for analyses. I have added variable labels using the right procedure. To add the corresponding values to few variables, I used PROC FORMAT:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc format; 
	VALUE HNCO1K 1="Very good" 2="Good"; 
	VALUE HTM50L 0="V" 1="G"; 
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;I would like to add the analogous values which I defined, using PROC FORMAT, to each of the 594 variables. Using the data step, I know I could apply the format as such to few variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA help_formatted2;

&amp;nbsp;&amp;nbsp;&amp;nbsp; SET help;

&amp;nbsp;&amp;nbsp;&amp;nbsp; FORMAT Rate HNCO1K. Code HTM50L.;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am struggling to find the most efficient way to add the values to all 594 variables in one attempt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I shall be most grateful for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 22:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805644#M1054</guid>
      <dc:creator>Zacc</dc:creator>
      <dc:date>2022-04-02T22:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805645#M1055</link>
      <description>&lt;P&gt;Would you need 594 different formats, or is there a rule to assign the two formats repeatedly?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 22:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805645#M1055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-02T22:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805646#M1056</link>
      <description>@ kurt_Bremser, thanks for your response.&lt;BR /&gt;Indeed, I would different formats for all 549 variables.</description>
      <pubDate>Sat, 02 Apr 2022 23:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805646#M1056</guid>
      <dc:creator>Zacc</dc:creator>
      <dc:date>2022-04-02T23:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805663#M1062</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/352245"&gt;@Zacc&lt;/a&gt;&amp;nbsp;To apply permanent formats use Proc Datasets and not a data step. Formats are defined in the descriptor portion of a SAS file (table) and to change them doesn't require to process the data. Proc Datasets allows you to manipulate the descriptor portion.&lt;/P&gt;
&lt;P&gt;Below code demonstrates how this works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given you have so many variables: IF there would be some naming pattern that allows to derive the format name based on variable name (like: varname &lt;EM&gt;abc&lt;/EM&gt;, related format name &lt;EM&gt;abc_fmt&lt;/EM&gt;) then one could generate the proc datasets code - else you will have to type this for all the 549 variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $sex
    'M'='Male'
    'F'='Female'
    ;
  value age
    10-&amp;lt;14 ='Below 14'
    14-high='14 and older'
    ;
run;

data work.class;
  set sashelp.class;
run;

proc datasets lib=work nolist;
  modify class;
    format
      sex $sex.
      age age.
      ;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Apr 2022 01:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805663#M1062</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-04-03T01:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805682#M1064</link>
      <description>&lt;P&gt;To automate that, you must first set a rule which controls which format shall apply to which variable. This can be logic based upon the names, or a complete list of variable/format pairs in a dataset.&lt;/P&gt;
&lt;P&gt;Which of those do you have?&lt;/P&gt;</description>
      <pubDate>Sun, 03 Apr 2022 06:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805682#M1064</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-03T06:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805693#M1065</link>
      <description>&lt;P&gt;The names of each variable in the dataset are the same (i.e. "&lt;SPAN&gt;complete list of variable/format pairs"&lt;/SPAN&gt;) as the specified VALUE names in the PROC FORMAT .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Apr 2022 10:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805693#M1065</guid>
      <dc:creator>Zacc</dc:creator>
      <dc:date>2022-04-03T10:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805694#M1066</link>
      <description>&lt;P&gt;Then you can dynamically create the PROC DATASETS code from SASHELP.VTABLE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vcolumn end=done;
where libname = "LIBRARY" and memname = "DATASETS";
if _n_ = 1 then call execute("
  proc datasets library=LIBRARY nolist;
  modify DATASET;
  format
");
call execute(name !! " " !! trim(name) !! ".");
if done then call execute("
  ;
  quit;
");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you can store the value pairs for the FORMAT statement in a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name !! trim(name) !! "." into :formats separated by " "
from dictionary.columns
where libname = "LIBRARY" and memname = "DATASET";
quit;

proc datasets library=LIBRARY nolist;
modify DATASET;
format &amp;amp;formats.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace LIBRARY and DATASET with your library reference and dataset name; in the WHERE conditions, they must be uppercase.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Apr 2022 11:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805694#M1066</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-03T11:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Multiple Values to a Dataset Using PROC FORMAT</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805769#M1071</link>
      <description>Thank you so very @ Kurt_Bremser.</description>
      <pubDate>Mon, 04 Apr 2022 01:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Adding-Multiple-Values-to-a-Dataset-Using-PROC-FORMAT/m-p/805769#M1071</guid>
      <dc:creator>Zacc</dc:creator>
      <dc:date>2022-04-04T01:42:56Z</dc:date>
    </item>
  </channel>
</rss>

