<?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: Formatting Over a Hundred Variables in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524929#M142786</link>
    <description>&lt;P&gt;.. What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Jan 2019 21:40:04 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-01-06T21:40:04Z</dc:date>
    <item>
      <title>Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524900#M142768</link>
      <description>&lt;P&gt;Is there an efficient way to format over a hundred variables in SAS?&amp;nbsp;For example, for every variable, I am currently applying an fname for it. Ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format sex sexf. occ occf. ptcare ptcaref. shift shiftf.&lt;BR /&gt;specialty specialtyf. dept deptf. loc locf. **bleep** prickf.&lt;BR /&gt;sharps sharpsf. sharpsyr sharpsyrf. injrecap injrecapf.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, because I have a long list of variables, can I use multiple rows to mention the variables and their fnames? Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524900#M142768</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-01-06T16:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524901#M142769</link>
      <description>&lt;P&gt;Seems like the names of the formats in this example are always the name of the relevant variable with an 'f' on the end. Does that logic hold?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524901#M142769</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-06T16:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524903#M142770</link>
      <description>&lt;P&gt;Thanks! Yes, those are the formats I have been applying. My question is if there is a more efficient way to apply formats if I have a large number of variables. I have about 131 variables to format. Is this the only way to format my variables, by formatting them one by one? Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524903#M142770</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-01-06T16:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524904#M142771</link>
      <description>&lt;P&gt;Is there some logic that tells you what those 131 variables are? Are those 131 variables all of the variables from the data set?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:29:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524904#M142771</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-06T16:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524907#M142772</link>
      <description>&lt;P&gt;Yes, all 131 variables are from the same dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 16:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524907#M142772</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-01-06T16:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524910#M142774</link>
      <description>&lt;P&gt;Yes, but are those &lt;STRONG&gt;all&amp;nbsp;&lt;/STRONG&gt;the variables from that data set? Does the data set contain more than those 131 variables?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 17:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524910#M142774</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-06T17:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524916#M142777</link>
      <description>&lt;P&gt;Yes, those are all of the variables in the dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 17:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524916#M142777</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-01-06T17:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524921#M142781</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/213376"&gt;@JackZ295&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there an efficient way to format over a hundred variables in SAS?&amp;nbsp;For example, for every variable, I am currently applying an fname for it. Ex:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;format sex sexf. occ occf. ptcare ptcaref. shift shiftf.&lt;BR /&gt;specialty specialtyf. dept deptf. loc locf. **bleep** prickf.&lt;BR /&gt;sharps sharpsf. sharpsyr sharpsyrf. injrecap injrecapf.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, because I have a long list of variables, can I use multiple rows to mention the variables and their fnames? Thanks!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can definitely use multiple lines for a single SAS statement.&amp;nbsp; The SAS parser in general ignores end of lines and treats them like any other white space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format
  sex sexf.
  occ occf.
  ptcare ptcaref.
  shift shiftf.
  specialty specialtyf.
  dept deptf.
  loc locf.
....
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want help generating that statement you could potentially read the metadata on an existing dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=contents; run;
proc sql noprint ;
  select catx('=',name,cats(name,'f.'))
    into :fmtlist separated by ' '
  from contents
  ;
quit;
proc datasets nolist lib=work ;
  modify have ;
  format &amp;amp;fmtlist;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it would probably be better to have the metadata already in a dataset somewhere.&amp;nbsp; That would also allow you to not make multiple formats that use the same set of code/decode pairs.&amp;nbsp; For example is normal to have multiple variables that all use the response pattern, like YES/NO or a scale from 1 to 10.&amp;nbsp; So instead of making multiple format just make one and attach to all variables that need it.&amp;nbsp; So your metadata might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datasets ;
  infile cards dsd dlm='|' truncover ;
  input memname :$32. memlabel :$256. ;
cards;
ae|Adverse Events
demo|Patient Demographics
;

data variables ;
  infile cards dsd dlm='|' truncover ;
  input memname :$32. name :$32. type :$4. length format :$41. informat :$41. label :$256. ;
cards;
ae|id|char|10|||Patient Identifier
ae|aedate|num|8|date9.|date9.|Date of Adverse Event
ae|aename|char|40|||Adverse Event description
ae|aeser|num|8|yesno.||Serious AE?
demo|id|char|10|||Patient Identifier
demo|age|num|8|||Patient Age at enrollment
demo|enrolldt|num|8|date9.|date9.|Date of enrollment
demo|active|num|8|yesno.||Active?
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you could then use to generate a program. Perhaps something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp ;
data _null_;
  file code ;
  merge datasets variables ;
  by memname ;
  if first.memname then put 'data ' memname '(label=' memlabel :$quote. ');' ;
  put '  attrib ' name 'length=' @ ;
  if type='char' then put '$' @ ;
  put length @ ;
  if not missing(format) then put format= @;
  if not missing(informat) then put informat= @;
  if not missing(label) then put label = $quote. @ ;
  put ';' ;
  if last.memname then put '  stop;' / 'run;' / ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to get a program like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ae (label="Adverse Events" );
  attrib id length=$10 label="Patient Identifier" ;
  attrib aedate length=8 format=date9. informat=date9. label="Date of Adverse Event" ;
  attrib aename length=$40 label="Adverse Event description" ;
  attrib aeser length=8 format=yesno. label="Serious AE?" ;
  stop;
run;

data demo (label="Patient Demographics" );
  attrib id length=$10 label="Patient Identifier" ;
  attrib age length=8 label="Patient Age at enrollment" ;
  attrib enrolldt length=8 format=date9. informat=date9. label="Date of enrollment" ;
  attrib active length=8 format=yesno. label="Active?" ;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 18:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524921#M142781</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-06T18:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524929#M142786</link>
      <description>&lt;P&gt;.. What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 21:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524929#M142786</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-06T21:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524961#M142804</link>
      <description>&lt;P&gt;While&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;gave you a few good approaches, you also have to consider whether this might be a bad idea.&amp;nbsp; If you assign the formats as part of a DATA step, those formats are permanently associated with the variables.&amp;nbsp; As a result, any time you want to use the data, all 131 formats must exist.&amp;nbsp; Is that an acceptable situation?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 03:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/524961#M142804</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-07T03:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/525932#M143122</link>
      <description>&lt;P&gt;I'm confused by what you mean when you say that any time I want to use the data, all 131 formats have to exist. Can you elaborate on your response? Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 23:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/525932#M143122</guid>
      <dc:creator>JackZ295</dc:creator>
      <dc:date>2019-01-09T23:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Over a Hundred Variables in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/525953#M143135</link>
      <description>&lt;P&gt;Let's say you have this situation where the format is permanently attached to a variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data with_format;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;format sex sexf.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's fine as long as the format exists.&amp;nbsp; But if you later use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set with_format;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the format must exist or else you will get an error message.&amp;nbsp; You can program around that.&amp;nbsp; This statement requests that there is no error message when a required format cannot be found:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options nofmterr;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But once you permanently associate a format with a variable, you need that format to exist when you use the data set.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2019 01:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-Over-a-Hundred-Variables-in-SAS/m-p/525953#M143135</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-10T01:35:18Z</dc:date>
    </item>
  </channel>
</rss>

