<?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 Issue with Sorting in Chronological Order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951761#M372022</link>
    <description>&lt;P&gt;I have the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data docvisits;
	input patientID $ weekday $ score;
	cards;
101	Friday    15
163	Wednesday 11
104	Friday    23
163	Thursday  13
123	Tuesday	10
104	Monday	20
157	Friday	21
101	Monday	10
112	Tuesday	11
157	Tuesday	10
123	Monday	9
123	Friday	9
101	Tuesday	11
112	Monday	9
157	Thursday  18
174	Monday	12
;

proc format;
    value $weekdayfmt
        'Monday' = 1
        'Tuesday' = 2
        'Wednesday' = 3
        'Thursday' = 4
        'Friday' = 5;
run;

data docvisits_sorted;
    set docvisits;
    daynum = input(weekday, $weekdayfmt.); 
run;


proc sql;
   select weekday, count(distinct patientID) as Total_Patients
   from docvisits_sorted
   group by weekday
   order by daynum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, there is &lt;U&gt;&lt;STRONG&gt;no output&lt;/STRONG&gt;&lt;/U&gt;. My goal is to list the days of the week that visits were on and the total number of patients who visited each day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Prior to the one above, I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data docvisits;
	input patientID$ weekday$5-13 score;
	cards;
101	Friday    15
163	Wednesday 11
104	Friday    23
163	Thursday  13
123	Tuesday	10
104	Monday	20
157	Friday	21
101	Monday	10
112	Tuesday	11
157	Tuesday	10
123	Monday	9
123	Friday	9
101	Tuesday	11
112	Monday	9
157	Thursday  18
174	Monday	12
;

proc sql;
   select weekday, count(distinct patientID) as Total_Patients
   from docvisits
   group by weekday;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, this does not output the days in chronological order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I fix my problem?&lt;/P&gt;</description>
    <pubDate>Mon, 25 Nov 2024 09:44:22 GMT</pubDate>
    <dc:creator>unwashedhelimix</dc:creator>
    <dc:date>2024-11-25T09:44:22Z</dc:date>
    <item>
      <title>Issue with Sorting in Chronological Order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951761#M372022</link>
      <description>&lt;P&gt;I have the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data docvisits;
	input patientID $ weekday $ score;
	cards;
101	Friday    15
163	Wednesday 11
104	Friday    23
163	Thursday  13
123	Tuesday	10
104	Monday	20
157	Friday	21
101	Monday	10
112	Tuesday	11
157	Tuesday	10
123	Monday	9
123	Friday	9
101	Tuesday	11
112	Monday	9
157	Thursday  18
174	Monday	12
;

proc format;
    value $weekdayfmt
        'Monday' = 1
        'Tuesday' = 2
        'Wednesday' = 3
        'Thursday' = 4
        'Friday' = 5;
run;

data docvisits_sorted;
    set docvisits;
    daynum = input(weekday, $weekdayfmt.); 
run;


proc sql;
   select weekday, count(distinct patientID) as Total_Patients
   from docvisits_sorted
   group by weekday
   order by daynum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, there is &lt;U&gt;&lt;STRONG&gt;no output&lt;/STRONG&gt;&lt;/U&gt;. My goal is to list the days of the week that visits were on and the total number of patients who visited each day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Prior to the one above, I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data docvisits;
	input patientID$ weekday$5-13 score;
	cards;
101	Friday    15
163	Wednesday 11
104	Friday    23
163	Thursday  13
123	Tuesday	10
104	Monday	20
157	Friday	21
101	Monday	10
112	Tuesday	11
157	Tuesday	10
123	Monday	9
123	Friday	9
101	Tuesday	11
112	Monday	9
157	Thursday  18
174	Monday	12
;

proc sql;
   select weekday, count(distinct patientID) as Total_Patients
   from docvisits
   group by weekday;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, this does not output the days in chronological order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I fix my problem?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 09:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951761#M372022</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-11-25T09:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Sorting in Chronological Order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951772#M372026</link>
      <description>&lt;P&gt;Try below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 invalue $weekdayfmt
 'Monday' = 1
 'Tuesday' = 2
 'Wednesday' = 3
 'Thursday' = 4
 'Friday' = 5;
run;

proc sql;
  select weekday, count(distinct patientID) as Total_Patients
  from docvisits
  group by weekday
  order by input(weekday, $weekdayfmt.)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that you need to create in INformat (proc format INvalue) for reading data with an input statement. Formats are for writing (put statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 10:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951772#M372026</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-25T10:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Sorting in Chronological Order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951774#M372027</link>
      <description>&lt;P&gt;Calendar days should be represented as valid &lt;U&gt;numeric&lt;/U&gt; SAS date values. Then sorting is easy and determining the day of week is easy. This is an extremely good habit to get into, and will save you tons of effort in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As soon as you make calendar information character, you then have to go through extra steps to make it sort properly.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2024 10:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951774#M372027</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-25T10:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Sorting in Chronological Order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951885#M372078</link>
      <description>&lt;P&gt;&lt;EM&gt;Your PROC FORMAT is NOT right.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data docvisits;
	input patientID $ weekday :$20. score;
	cards;
101	Friday    15
163	Wednesday 11
104	Friday    23
163	Thursday  13
123	Tuesday	10
104	Monday	20
157	Friday	21
101	Monday	10
112	Tuesday	11
157	Tuesday	10
123	Monday	9
123	Friday	9
101	Tuesday	11
112	Monday	9
157	Thursday  18
174	Monday	12
;

proc format;
    invalue weekdayfmt
        'Monday' = 1
        'Tuesday' = 2
        'Wednesday' = 3
        'Thursday' = 4
        'Friday' = 5;
run;

data docvisits_sorted;
    set docvisits;
    daynum = input(weekday, weekdayfmt.); 
run;


proc sql nowarn;
   select distinct weekday, count(distinct patientID) as Total_Patients
   from docvisits_sorted
   group by weekday
   order by daynum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2024 02:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Sorting-in-Chronological-Order/m-p/951885#M372078</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-26T02:17:50Z</dc:date>
    </item>
  </channel>
</rss>

