<?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 Applying a specific (user created) format name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697503#M213163</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to apply a new format to my data, but whenever I try and use the format, I get "Unexpected Value" in the output. However, when I change the format name by even one letter - adding one, deleting one, or changing one in the middle - I get the results I am looking for. This is a project for a class which requires a specific format name ($StateCd), otherwise I would accept the results as they are and not be as picky. I thought maybe the fact that it is the same name as the renamed variable, but even when I do not rename the variable, the format still does not work. If anyone has any input on why and how to fix it, I would really appreciate it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
VALUE $StateCd
		' '				= 'Unknown'
		'Ohio' 			= 'OH'
		'Delaware' 	    = 'DE'
		'Alaska' 	    = 'AS'
		OTHER 			= 'Unexpected Value';
	RUN;
	
DATA	WORK.Contact_Ohio;
	SET	HypImpt.OhioResidents	(RENAME= (Initials= Inits
										  State=StateCd)
								);
	KEEP SSN Inits City StateCd ZipCd;
	Inits	=	CATS(	SUBSTR(Inits, 1, 1),	
						SUBSTR(Inits, 3, 1),
						SUBSTR(Inits, 4, 1)
					);

	
	RUN;


PROC PRINT DATA = WORK.Contact_OH;
	FORMAT StateCd $StateCd.;
	RUN;
	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are no errors or warnings in the log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2020 15:18:03 GMT</pubDate>
    <dc:creator>sdevenny</dc:creator>
    <dc:date>2020-12-10T15:18:03Z</dc:date>
    <item>
      <title>Applying a specific (user created) format name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697503#M213163</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to apply a new format to my data, but whenever I try and use the format, I get "Unexpected Value" in the output. However, when I change the format name by even one letter - adding one, deleting one, or changing one in the middle - I get the results I am looking for. This is a project for a class which requires a specific format name ($StateCd), otherwise I would accept the results as they are and not be as picky. I thought maybe the fact that it is the same name as the renamed variable, but even when I do not rename the variable, the format still does not work. If anyone has any input on why and how to fix it, I would really appreciate it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
VALUE $StateCd
		' '				= 'Unknown'
		'Ohio' 			= 'OH'
		'Delaware' 	    = 'DE'
		'Alaska' 	    = 'AS'
		OTHER 			= 'Unexpected Value';
	RUN;
	
DATA	WORK.Contact_Ohio;
	SET	HypImpt.OhioResidents	(RENAME= (Initials= Inits
										  State=StateCd)
								);
	KEEP SSN Inits City StateCd ZipCd;
	Inits	=	CATS(	SUBSTR(Inits, 1, 1),	
						SUBSTR(Inits, 3, 1),
						SUBSTR(Inits, 4, 1)
					);

	
	RUN;


PROC PRINT DATA = WORK.Contact_OH;
	FORMAT StateCd $StateCd.;
	RUN;
	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are no errors or warnings in the log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697503#M213163</guid>
      <dc:creator>sdevenny</dc:creator>
      <dc:date>2020-12-10T15:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a specific (user created) format name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697505#M213164</link>
      <description>&lt;P&gt;Could it be that your statecd is not left-aligned (has leading blanks)?&lt;/P&gt;
&lt;P&gt;See this for reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FORMAT;
VALUE $StateCd
    ' '       = 'Unknown'
    'IOWA'      = 'IA'
    'MISSISSIPPI'   = 'MS'
    'UTAH'      = 'UT'
    OTHER       = 'Unexpected Value';
  RUN;
  
data test;
input statecd $char20.;
datalines;
IOWA
  IOWA
;

proc print data=test;
format statecd $statecd.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 05:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697505#M213164</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-09T05:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a specific (user created) format name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697515#M213168</link>
      <description>&lt;P&gt;If you can't find leading blanks, check the spelling: do you have "IOWA" or "Iowa" in the data?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 06:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697515#M213168</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-11-09T06:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a specific (user created) format name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697647#M213235</link>
      <description>&lt;P&gt;A previous example I explained that your values in the data must match exactly as defined in the format.&lt;/P&gt;
&lt;P&gt;So, are all of your values all upper case for statecd? No leading blanks?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, have you even considered the ZIP functions I mentioned? The previous very limited output you showed results that would not be generated by your format, so it seems that you have actual values of "Unknown" in your data, or similar, and those would get mapped to the OTHER category.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or it is time to actually share your input data.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 15:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-a-specific-user-created-format-name/m-p/697647#M213235</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-09T15:40:34Z</dc:date>
    </item>
  </channel>
</rss>

