<?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: Format help in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715461#M27366</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364982"&gt;@nduksy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Day and Month are both numeric characters&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;aka as round squares?&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 21:31:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-01-29T21:31:07Z</dc:date>
    <item>
      <title>Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715453#M27360</link>
      <description>&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I will appreciate your assistance in reviewing the attached code.&lt;/DIV&gt;&lt;DIV&gt;Some background - the holiday data has a day and month column (both numeric). I&amp;nbsp; concatenated them, the concatenated data displays something like this 1-12&amp;nbsp; (i.e. December 1).&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I used the format function to format the numeric months as character months so I can present something such as - '&lt;STRONG&gt;December 1&lt;/STRONG&gt;' in my output.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When I run it, the '&lt;STRONG&gt;Day and Month&lt;/STRONG&gt;' column is empty&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you in anticipation.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;/*Concatenating Day and Moth*/
data derive.holiday;
	set holiday;
	DayMonth = month ||'-'|| day;
run;

/*Formatting numeric Month to Character Month*/
proc format;
value $CharMonth '1' = 'January'
		 '2' = 'February'
		 '3' = 'March'
		 '4' = 'April'
		 '5' = 'May'
		 '6' = 'June'
		 '7' = 'July'
		 '8' = 'August'
		 '9' = 'September'
		 '10' = 'October'
		 '11' = 'November'
		 '12' = 'December'
		;
run;

/*Applying informat to data*/
data derive.holiday;
	set holiday;
	format month $CharMonth.;
run;

/*Printing Holiday*/
proc printto print ='C:\Users\nduka\Documents\SAS Training\Studies\Clinical\Data\output\HolidayReport.txt' new;
run;

proc report data = derive.holiday nowd headskip split='/';
	title 'List of holidays';
	footnote 'Created by Nduka Oluku';
	column name desc day month DayMonth begin;
	define name/display 'Holiday Name' width=25;
	define desc/display 'Holiday Description' width=30;
	define day/display 'Day' width=3;
	define month/display 'Month' width=5;
	define DayMonth/display 'Day &amp;amp; Month' width=20 format=$CharMonth.;
	define begin/display 'Year Started' width=20;
	break after name /skip;
	compute after;
	line ' ';
	endcomp;
	
run;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 29 Jan 2021 20:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715453#M27360</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-01-29T20:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715456#M27361</link>
      <description>&lt;P&gt;Start at the beginning.&amp;nbsp; Examine the variable DayMonth in your top DATA step.&amp;nbsp; What do you want it to contain?&amp;nbsp; Is it character or numeric?&amp;nbsp; What is its length?&amp;nbsp; What is its value?&amp;nbsp; That should narrow down where you need to fix things.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715456#M27361</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-01-29T21:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715457#M27362</link>
      <description>&lt;P&gt;In your first step, you create a dataset &lt;EM&gt;with&lt;/EM&gt; variable daymonth.&lt;/P&gt;
&lt;P&gt;In the second step, you create a format.&lt;/P&gt;
&lt;P&gt;In the third step, you overwrite the dataset you created in the first step,&amp;nbsp;&lt;EM&gt;without&lt;/EM&gt; daymonth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you can't expect any values in daymonth.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715457#M27362</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T21:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715458#M27363</link>
      <description>&lt;P&gt;Thanks for pointing out the issue. Can you advise on what I need to do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715458#M27363</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-01-29T21:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715459#M27364</link>
      <description>&lt;P&gt;The variables day and month - are they char type or numeric?&lt;/P&gt;
&lt;P&gt;Are there any messages in the log?&lt;/P&gt;
&lt;P&gt;Can you post the output you got?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The order of your steps is not clear - on first step you created a new variable named &lt;STRONG&gt;DayMonth&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;On next step (excluding proc format) you override the output dataset &lt;STRONG&gt;delivery.holiday&lt;/STRONG&gt; and you &lt;U&gt;lost&lt;/U&gt; the DayMonth variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to save the output report to a file you need to run &lt;STRONG&gt;proc printto&lt;/STRONG&gt; twice - the first, as you have done, is to to assign the outfile name. The 2nd should be after proc report and&amp;nbsp; is to close the file by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:26:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715459#M27364</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-29T21:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715460#M27365</link>
      <description>&lt;P&gt;Day and Month are both numeric characters&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715460#M27365</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-01-29T21:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715461#M27366</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/364982"&gt;@nduksy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Day and Month are both numeric characters&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;aka as round squares?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715461#M27366</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T21:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715463#M27367</link>
      <description>&lt;P&gt;I am sorry, they are numeric&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715463#M27367</guid>
      <dc:creator>nduksy</dc:creator>
      <dc:date>2021-01-29T21:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Format help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715465#M27368</link>
      <description>&lt;P&gt;First some details you need to provide.&lt;/P&gt;
&lt;P&gt;Are your original Day and Month variables character or numeric?&lt;/P&gt;
&lt;P&gt;Second you define the format to use values 1 through 12 but then apply them to a value Daymonth that you think is "12-1". Since you do not have the value "12-1" in the format it does not get applied and the value is likely shown. But depending on the format when you create DayMonth you likely have values with spaces due to using the || operator.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data example;
   day=1;
   month=12;
   daymonth = month||'-'||day;
run;&lt;/PRE&gt;
&lt;P&gt;Which will have an actual value (pasting into a text box because the forum will reformat the text to much shorter)&lt;/P&gt;
&lt;PRE&gt;Daymonth="          12-           1"&lt;/PRE&gt;
&lt;P&gt;because the default format for numeric variables as I created that is BEST12 and the conversion to character that takes place using the || operator uses the default format and right justifies the result. So there are LOTS of spaces, 10 before the 12 and 11 before the 1.&lt;/P&gt;
&lt;P&gt;Here is a large economy sized hint: when storing any value that might resemble a date then create an actual date with a year month and day of the month. Then you can create formats that will work a bit more consistently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a format that would display "12-1"&amp;nbsp; "12-2" ... "12-31" you would have to list each value to display December. Ranges work oddly if you try to use them with character values. I'll leave this as an exercise for the interested reader.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another issue is what can happen using character formats with undefined values and default display lengths. Using your format and the data I created above:&lt;/P&gt;
&lt;PRE&gt;proc print data=example;
    title "Simple format use $charmonth.";
   format daymonth $charmonth.;
run; title;

proc print data=example;
    title "use $charmonth20.";
   format daymonth $charmonth20.;
run; title;&lt;/PRE&gt;
&lt;P&gt;You will see that Daymonth does not appear to be in the first proc print output and only appears partially in the second. Using an explicit width with the format, such as $charmonth20. it will force displaying up to 20 characters if available. Since there are lots of spaces between the - and the 1 for days that still isn't wide enough. Sometimes when creating format you need to specify a default display length as well. Follows an example with a date type numeric value and format with directives to display month and day. SAS supplies a format MONNAME that will display any date just as the name, but you do need a complete date value to use it.&lt;/P&gt;
&lt;PRE&gt;data example2;
   day=1;
   month=12;
   date = mdy(12,1,1960);
run;

proc format;
picture Month_day  (default=15)
low-high = '%B-%d' (datatype=date)
;

proc print data=example2;
   format date month_day.;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Format-help/m-p/715465#M27368</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-29T21:37:15Z</dc:date>
    </item>
  </channel>
</rss>

