<?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: PROC FORMAT in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67130#M19190</link>
    <description>Thanks, DBailey. Another way to work this out. Worked!</description>
    <pubDate>Thu, 19 May 2011 12:04:14 GMT</pubDate>
    <dc:creator>bncoxuk</dc:creator>
    <dc:date>2011-05-19T12:04:14Z</dc:date>
    <item>
      <title>PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67125#M19185</link>
      <description>I used the PROC FORMAT to create a new format called sexf:&lt;BR /&gt;
&lt;BR /&gt;
PROC FORMAT;&lt;BR /&gt;
   VALUE $sexf   &lt;BR /&gt;
   'F' = 'Female'&lt;BR /&gt;
   'M' = 'Male'&lt;BR /&gt;
    ;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
I then tried to use this format to format the exsting variable (sex) in a file called file01. The variable has two values: 'M', 'F'. However, this variable still retails the values as 'M' and 'F' in the new dataset file02, but the new variable sex1 works OK with values as 'Female' and 'Male'.&lt;BR /&gt;
&lt;BR /&gt;
DATA work.file02;&lt;BR /&gt;
    SET work.file01;&lt;BR /&gt;
    LENGTH sex $8;       /*to change the length from 1 to 8*/&lt;BR /&gt;
    sex=PUT(sex,$sexf.);&lt;BR /&gt;
    sex1=PUT(sex,$sexf.);&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Can you please tell what is the problem? Thanks in advance.</description>
      <pubDate>Wed, 18 May 2011 17:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67125#M19185</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-05-18T17:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67126#M19186</link>
      <description>Hello Bncoxuk,&lt;BR /&gt;
&lt;BR /&gt;
The problem is that your sex variable in the file02 dataset still has a length of 1 (the length is inherited from file01). To get what you need it is necessary to place LENGTH before SET.&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 18 May 2011 17:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67126#M19186</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-18T17:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67127#M19187</link>
      <description>If you want the Female/Male values displayed in PROC output just associate the format with the variable instead of increasing the space needed in the data set.&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT DATA = WORK.FILE01;&lt;BR /&gt;
   VAR SEX;&lt;BR /&gt;
   FORMAT SEX $SEXF.;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
or add the FORMAT SEX $SEXF.; statement to DATA work.file02 to permanently associate the format and make it the default appearance.</description>
      <pubDate>Wed, 18 May 2011 22:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67127#M19187</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-05-18T22:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67128#M19188</link>
      <description>I tried but still got the same problem. The LENGTH statement moved before the SET statement, but the variable Sex still keeps the original value, instead of using the format defined by PROC FORMAT.</description>
      <pubDate>Thu, 19 May 2011 09:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67128#M19188</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-05-19T09:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67129#M19189</link>
      <description>DATA work.file02(drop=sex);&lt;BR /&gt;
SET work.file01;&lt;BR /&gt;
format gender $8;&lt;BR /&gt;
if sex='M' then gender='Male';&lt;BR /&gt;
else gender='Female';&lt;BR /&gt;
RUN;</description>
      <pubDate>Thu, 19 May 2011 11:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67129#M19189</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-05-19T11:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67130#M19190</link>
      <description>Thanks, DBailey. Another way to work this out. Worked!</description>
      <pubDate>Thu, 19 May 2011 12:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67130#M19190</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-05-19T12:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67131#M19191</link>
      <description>Are you wanting to store Sex as "male" "female" or just have it so it displays as "male" "female" in SEX variable?&lt;BR /&gt;
&lt;BR /&gt;
See if this helps for whichever way you're wanting to do it.&lt;BR /&gt;
&lt;BR /&gt;
*****************&lt;BR /&gt;
PROC FORMAT;&lt;BR /&gt;
VALUE $sexf &lt;BR /&gt;
'F' = 'Female'&lt;BR /&gt;
'M' = 'Male'&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
****************&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
INPUT NAME $8. SEX $1. ;&lt;BR /&gt;
DATALINES;&lt;BR /&gt;
ADAMS   M&lt;BR /&gt;
LINCOLN	F&lt;BR /&gt;
ROGERS  M&lt;BR /&gt;
HILTON  F&lt;BR /&gt;
SMITH   X&lt;BR /&gt;
;&lt;BR /&gt;
RUN;  *** use X to show one that doesn't fit the format ***;&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT DATA=TEST; RUN; *** sex stored as M/F ***;&lt;BR /&gt;
PROC PRINT DATA=TEST; FORMAT SEX $SEXF.; RUN; *** sex still stored as M/F ***;&lt;BR /&gt;
PROC CONTENTS DATA=TEST; RUN; *** see no permanent format applied ***;&lt;BR /&gt;
&lt;BR /&gt;
DATA file02;&lt;BR /&gt;
SET TEST;&lt;BR /&gt;
format sex3 $sexf.;&lt;BR /&gt;
sex1=PUT(sex,$sexf.); *** stores as Male/Female ***;&lt;BR /&gt;
sex2=sex;  *** stores as M/F ***;&lt;BR /&gt;
sex3=sex;  *** stores as M/F, displays as Male/Female ***;&lt;BR /&gt;
RUN;&lt;BR /&gt;
PROC PRINT DATA=FILE02; RUN;&lt;BR /&gt;
PROC CONTENTS DATA=FILE02; RUN;	*** permanent format applied to sex3 only ***;&lt;BR /&gt;
&lt;BR /&gt;
data file02;&lt;BR /&gt;
LENGTH sex $6; /*to change the length from 1 to 8 */&lt;BR /&gt;
set file02;&lt;BR /&gt;
sex=put(sex, $sexf.); *** stores as Male/Female ***;&lt;BR /&gt;
run;&lt;BR /&gt;
PROC PRINT DATA=FILE02; RUN;&lt;BR /&gt;
PROC CONTENTS DATA=FILE02; RUN;</description>
      <pubDate>Thu, 19 May 2011 12:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67131#M19191</guid>
      <dc:creator>stateworker</dc:creator>
      <dc:date>2011-05-19T12:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67132#M19192</link>
      <description>Hello Bncoxuk,&lt;BR /&gt;
&lt;BR /&gt;
I use EG 4.3 and tested the suggestion I provided. If LENGTH is before SET then everything works as expected. This is a program that I tested:&lt;BR /&gt;
[pre]&lt;BR /&gt;
PROC FORMAT;&lt;BR /&gt;
  VALUE $sexf &lt;BR /&gt;
  'F' = 'Female'&lt;BR /&gt;
  'M' = 'Male'&lt;BR /&gt;
  ;&lt;BR /&gt;
RUN;&lt;BR /&gt;
DATA class;&lt;BR /&gt;
  LENGTH sex $8; /*to change the length from 1 to 8*/&lt;BR /&gt;
  SET sashelp.class;&lt;BR /&gt;
  sex=PUT(sex,$sexf.);&lt;BR /&gt;
  sex1=PUT(sex,$sexf.);&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR

Message was edited by: SPR</description>
      <pubDate>Thu, 19 May 2011 13:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67132#M19192</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-19T13:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67133#M19193</link>
      <description>Hi SPR,&lt;BR /&gt;
&lt;BR /&gt;
Using your code, mine also worked now. Thanks a lot! &lt;BR /&gt;
&lt;BR /&gt;
bncoxuk</description>
      <pubDate>Mon, 23 May 2011 08:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67133#M19193</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-05-23T08:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67134#M19194</link>
      <description>In my case, one tricky thing is that the variable won't be formatted using the new format style. Very tricky!&lt;BR /&gt;
&lt;BR /&gt;
Right click the variable sex and see the Column Attributes. The format is still shown as $1. To resolve this problem, one more statement can be added immediately after the LENGTH statement: &lt;BR /&gt;
&lt;BR /&gt;
FORMAT sex $8.;&lt;BR /&gt;
&lt;BR /&gt;
Now the problem disappeared. I don't know why my data is different from the sashelp.class data. In fact, the format for sex in the class data is still shown as $1.</description>
      <pubDate>Mon, 23 May 2011 09:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67134#M19194</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2011-05-23T09:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FORMAT</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67135#M19195</link>
      <description>How about:&lt;BR /&gt;
[pre]&lt;BR /&gt;
format sex $sexf8.;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 24 May 2011 04:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FORMAT/m-p/67135#M19195</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-24T04:41:28Z</dc:date>
    </item>
  </channel>
</rss>

