<?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: AUTOMATED proc format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672670#M202178</link>
    <description>&lt;P&gt;Presumably you have a way to examine your data set to get the equivalent of all the values that appear, something equivalent to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data strata;
   input stratum $;
datalines;
A
0
1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice this is data, no macro language involved.&lt;/P&gt;
&lt;P&gt;With slight changes to this data, the process can be automated easily:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set strata;
   retain fmtname '$a';
   start = stratum;
   if stratum='0' then label = '0-Non-sepstrata';
   else label = catx('-', stratum, 'sepstrata');
run;
proc format cntlin=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is standard technique for creating a format using a SAS data set as input.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jul 2020 19:20:44 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-07-27T19:20:44Z</dc:date>
    <item>
      <title>AUTOMATED proc format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672536#M202132</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I've created a user defined format by using proc format statements.Would like to create a macro over it in a way that if the input data changes, the code should able to adjust the change accordingly.&lt;/P&gt;
&lt;P&gt;Here is the code: &lt;BR /&gt;`proc format ;&lt;BR /&gt;value $a 1='1-sepstrata'&lt;BR /&gt;0='0-Non-sepstrata'&lt;BR /&gt;A='A-sepstrata';&lt;BR /&gt;run;&lt;BR /&gt;`&lt;BR /&gt;In my current dateset I've,a columns named stratum which has unique values such as 1,0,A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly suggest how to go about solving this.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 14:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672536#M202132</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-27T14:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: AUTOMATED proc format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672544#M202134</link>
      <description>&lt;P&gt;And how is this automated process supposed to determine the display value when a new value appears in the data?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 14:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672544#M202134</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-27T14:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: AUTOMATED proc format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672578#M202145</link>
      <description>Hi ballardw, I'm also curious to know the same. what i have in the currently existing dataset is only the lefthand side values,(0,1,A) .I need to define it  based on a condition(which is if is it 0 then it should be "Non-sepstrata", otherwise anything else would have a "-sepstrata" attached to the value.&lt;BR /&gt;Something below i've tried and would like to try with a if statement but not been successful yet. &lt;BR /&gt;proc format ;&lt;BR /&gt;value $new_a %substr(&amp;amp;stratum,1)=%bquote(%substr(&amp;amp;stratum,1)||"-sepstrata") &lt;BR /&gt;      %substr(&amp;amp;stratum,2)=%bquote(%substr(&amp;amp;stratum,2)||"-sepstrata")&lt;BR /&gt;      %substr(&amp;amp;stratum,3)=%bquote(%substr(&amp;amp;stratum,3)||"-sepstrata")&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Jul 2020 15:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672578#M202145</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-27T15:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: AUTOMATED proc format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672580#M202147</link>
      <description>&lt;P&gt;If you have as input a macro variable with a delimited list of strata. Such as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let strata=0|1|A ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use a %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value $new_a 
%do index=1 %to %sysfunc(countw(&amp;amp;strata,|));
  %let stratum=%scan(&amp;amp;strata,&amp;amp;index,|);
  %if "&amp;amp;stratum"="0" %then %do;
    "&amp;amp;startum"="&amp;amp;stratum-Non-sepstrata"
  %end;
  %else %do;
    "&amp;amp;startum"="&amp;amp;stratum-sepstrata"
  %end;
%end;
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that to use %DO loop you need to code this inside of a macro.&lt;/P&gt;
&lt;P&gt;Note there is no need for macro quoting, but that you need to use double quotes around the values instead of single quotes so that SAS will evaluate the macro triggers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 15:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672580#M202147</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-27T15:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: AUTOMATED proc format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672620#M202160</link>
      <description>&lt;P&gt;It's too bad that your variable isn't numeric. It would be very easy with numeric values:&lt;/P&gt;
&lt;PRE&gt;proc format;
picture mypict
0 = '0-Non-sepstrata' (noedit)
other ='09-sepstrata'
;
run;


data _null_;
   do i=0 to 20;
   put i= mypict.;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;The log will show different values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the values you seem to have investigate the use of Proc FCMP to create a custom function that will create the string value XXX-sepstrata given a string value other than 1. Then the format would look like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc fcmp outlib=sasuser.funcs.sep;
   function sepstrata (str $ ) $ ;
      if str='0' then return('0-Non-sepstrata');
      else return(catx('-',str,'sepstrata'));
   endsub;
run;
/* make the function available*/
options cmplib=(sasuser.funcs);

proc format cntlout=work.ctl;
value $new_sep (default=20 )
other = [sepstrata()]
; 
run;

data _null_;
   length A $ 5;
   do a='0','1','A','B','Fred';
      put a= $new_sep,;
   end;
 
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jul 2020 17:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672620#M202160</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-27T17:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: AUTOMATED proc format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672670#M202178</link>
      <description>&lt;P&gt;Presumably you have a way to examine your data set to get the equivalent of all the values that appear, something equivalent to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data strata;
   input stratum $;
datalines;
A
0
1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice this is data, no macro language involved.&lt;/P&gt;
&lt;P&gt;With slight changes to this data, the process can be automated easily:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set strata;
   retain fmtname '$a';
   start = stratum;
   if stratum='0' then label = '0-Non-sepstrata';
   else label = catx('-', stratum, 'sepstrata');
run;
proc format cntlin=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is standard technique for creating a format using a SAS data set as input.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 19:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/AUTOMATED-proc-format/m-p/672670#M202178</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-07-27T19:20:44Z</dc:date>
    </item>
  </channel>
</rss>

