<?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: Is this a format problem? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695090#M33558</link>
    <description>&lt;P&gt;This is a perfect use case for PROC FORMAT. Create the format and apply with put(). I would also UPCASE() all of your values to make this conversion case-insensitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value $ethnic 
		'WHITE'='1' 
		'BLACK', 'AFRICAN AMERICAN'='2' 
		'AMERICAN INDIAN', other='3';
run;

data have;
	infile datalines dsd;
	input work :$20.;
	datalines;
White
Black
African American
Other
American Indian
z
;
run;

data want;
	set have;
	work_new=put(upcase(work), $ethnic.); /*Apply format*/
run;
proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2020 05:00:53 GMT</pubDate>
    <dc:creator>unison</dc:creator>
    <dc:date>2020-10-29T05:00:53Z</dc:date>
    <item>
      <title>Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695066#M33554</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I did data analysis with csv file on SAS, many character variables.&lt;/P&gt;&lt;P&gt;After running this code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="aw016_0-1603928873657.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51186iB04EF82E9823C661/image-size/medium?v=v2&amp;amp;px=400" role="button" title="aw016_0-1603928873657.png" alt="aw016_0-1603928873657.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got below notes and error, same errors showed up when I use&amp;nbsp; "where".&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="aw016_1-1603928453230.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51185i0B9B71BE86C0BBE5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="aw016_1-1603928453230.png" alt="aw016_1-1603928453230.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I wonder, how to remove the error? Do I need to format all variables before analysis?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 23:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695066#M33554</guid>
      <dc:creator>aw016</dc:creator>
      <dc:date>2020-10-28T23:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695068#M33555</link>
      <description>&lt;P&gt;Hard to reply when you post photographs of text.&amp;nbsp; The quotes in your font do not look like normal quotes to me. Make sure you don't have what Microsoft Word calls "smart" quotes (aka stupid quotes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will define a variable as soon as it has to based on the information at hand at that point.&lt;/P&gt;
&lt;P&gt;So if WORK does not exist then your code will make it as numeric because the first place you reference it you are comparing to a numeric missing.&amp;nbsp; If you want to check if a character variable is missing compare it to a blank string. Or use MISSING() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your last two lines are not code right.&amp;nbsp; You are testing if the strings C and Other are true or false since you have them as the right hand argument to the OR operator.&amp;nbsp; You probably want to use the IN operator instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if work in ('B','C') then ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2020 00:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695068#M33555</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-29T00:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695076#M33556</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;for your help!&lt;/P&gt;&lt;P&gt;This is my first time posting a question here, still exploring &lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt; I apologize for the inconvenient view of the picture, here is the original code:&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" color="#0000FF"&gt;data want_1; set want;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" color="#0000FF"&gt;if work=. then work_new=.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" color="#0000FF"&gt;else if work= "White" then work_new="1"; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" color="#0000FF"&gt;else if work="Black" or "African American" then work_new="2";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" color="#0000FF"&gt;else if work= "Other" or "American Indian" then work_new="3";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" color="#0000FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;The code you provided works for me to re-categorize the variable. The original file is .xlsx then transferred to .csv then put into the SAS. I actually didn't check if there are "smart quotes".&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 01:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695076#M33556</guid>
      <dc:creator>aw016</dc:creator>
      <dc:date>2020-10-29T01:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695083#M33557</link>
      <description>&lt;P&gt;The problem originates with this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if work=. then work_new=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The dot represents a missing value for a numeric variable.&amp;nbsp; Therefore,&amp;nbsp; the program creates WORK_NEW as a numeric variable, unable to hold character values like "1" and "2".&amp;nbsp; Start with this statement instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if work=. then work_new=" ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will give you a missing value for a character variable, able to hold values like "1" and "2".&amp;nbsp; You still need to switch to the IN operator as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;suggested.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 02:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695083#M33557</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-10-29T02:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695090#M33558</link>
      <description>&lt;P&gt;This is a perfect use case for PROC FORMAT. Create the format and apply with put(). I would also UPCASE() all of your values to make this conversion case-insensitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value $ethnic 
		'WHITE'='1' 
		'BLACK', 'AFRICAN AMERICAN'='2' 
		'AMERICAN INDIAN', other='3';
run;

data have;
	infile datalines dsd;
	input work :$20.;
	datalines;
White
Black
African American
Other
American Indian
z
;
run;

data want;
	set have;
	work_new=put(upcase(work), $ethnic.); /*Apply format*/
run;
proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 05:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695090#M33558</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-10-29T05:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695097#M33562</link>
      <description>&lt;P&gt;Variables should always be defined by using length or attrib-statement. This is especially important for char-variables, because if you omit the declaration, the first assignment defines the length - often to short to hold the values assigned later on.&lt;/P&gt;
&lt;P&gt;And &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270457"&gt;@unison&lt;/a&gt; is absolutely right: this is a job for a format. And this one of the rare cases in which i would use an informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   invalue $ethnic (upcase) /* all values are automatically upcased */
      'WHITE' = '1' 
      'BLACK', 'AFRICAN AMERICAN' = '2' 
      'AMERICAN INDIAN', other = '3'
  ;
run;

data want;
   set have;
   work_new = input(work, $ethnic.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2020 05:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695097#M33562</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-10-29T05:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is this a format problem?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695250#M33572</link>
      <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;! This is really helpful!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Is-this-a-format-problem/m-p/695250#M33572</guid>
      <dc:creator>aw016</dc:creator>
      <dc:date>2020-10-29T15:54:29Z</dc:date>
    </item>
  </channel>
</rss>

