<?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 Need to separate out a column, then arrange alphabetically with missing values last (character) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898015#M354939</link>
    <description>&lt;P&gt;I am trying to separate out a column as it currently has multiple effects listed in the individual column like so:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lexsc_sas_0-1696967754696.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88748iA5F13FB1494412A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lexsc_sas_0-1696967754696.png" alt="lexsc_sas_0-1696967754696.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I use the scan function and create different column names for the various symptoms.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lexsc_sas_1-1696967977757.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88749i98046DE9DF6B260C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lexsc_sas_1-1696967977757.png" alt="lexsc_sas_1-1696967977757.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From there, I would like to arrange them alphabetically but have the missing values be last (i.e. have the Symptom1 column be acidosis for all those who have that symptom) so that I can use the proc freq function to determine how many people total had each individual symptom.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using call sortc but this had all the missing values first (1 of the clinical effects had 23 different symptoms, but many only had 1 or 2 listed) and then would start the symptoms in alphabetical order so that the "acidosis" was in different numbers instead of always being symptom1 like I would like it to be.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lexsc_sas_2-1696968057357.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88750iA37F16A1ADFD56BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lexsc_sas_2-1696968057357.png" alt="lexsc_sas_2-1696968057357.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 20:01:49 GMT</pubDate>
    <dc:creator>lexsc_sas</dc:creator>
    <dc:date>2023-10-10T20:01:49Z</dc:date>
    <item>
      <title>Need to separate out a column, then arrange alphabetically with missing values last (character)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898015#M354939</link>
      <description>&lt;P&gt;I am trying to separate out a column as it currently has multiple effects listed in the individual column like so:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lexsc_sas_0-1696967754696.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88748iA5F13FB1494412A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lexsc_sas_0-1696967754696.png" alt="lexsc_sas_0-1696967754696.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I use the scan function and create different column names for the various symptoms.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lexsc_sas_1-1696967977757.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88749i98046DE9DF6B260C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lexsc_sas_1-1696967977757.png" alt="lexsc_sas_1-1696967977757.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From there, I would like to arrange them alphabetically but have the missing values be last (i.e. have the Symptom1 column be acidosis for all those who have that symptom) so that I can use the proc freq function to determine how many people total had each individual symptom.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using call sortc but this had all the missing values first (1 of the clinical effects had 23 different symptoms, but many only had 1 or 2 listed) and then would start the symptoms in alphabetical order so that the "acidosis" was in different numbers instead of always being symptom1 like I would like it to be.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lexsc_sas_2-1696968057357.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88750iA37F16A1ADFD56BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lexsc_sas_2-1696968057357.png" alt="lexsc_sas_2-1696968057357.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 20:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898015#M354939</guid>
      <dc:creator>lexsc_sas</dc:creator>
      <dc:date>2023-10-10T20:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need to separate out a column, then arrange alphabetically with missing values last (character)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898024#M354941</link>
      <description>Revisit your data structure. &lt;BR /&gt;Instead, put each symptom on a line by itself so you can summarize it. If that's not possible, I'd still do that, create a 0/1 variable and then transpose it so that each column is an indicator variable for the presence of a specific symptom.</description>
      <pubDate>Tue, 10 Oct 2023 20:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898024#M354941</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-10T20:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need to separate out a column, then arrange alphabetically with missing values last (character)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898025#M354942</link>
      <description>&lt;P&gt;Try to first separate distinct values into a single column, then sort it and transpose.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;eg;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input @1 id  @3 symptoms $ 3-100;
cards;
1 Dizziness/vertigo (NR),Vomitting (NR),Confusion (R)
2 Headache (R),Muscle weakness (R),Acidosis
3 Confusion (R)
4 Vomitting (NR),Headache (R)
; 
proc print;run; 

data have1;
	set have;
	num= countc(symptoms, ',');
	do i= 1 to num+1;
		Symptom= strip(scan(symptoms, i, ','));
		output;
	end;
	drop num i;
run; 
proc print; run; 

proc sort data= have1; 
	by id symptom; 
proc print; run; 

proc transpose data=have1 out=want (drop=_name_) prefix=Symptom;
	by id;
	var symptom;
proc print;run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2023 21:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898025#M354942</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-10-10T21:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need to separate out a column, then arrange alphabetically with missing values last (character)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898052#M354951</link>
      <description>&lt;P&gt;You have a character variable containing a comma-separated list.&amp;nbsp; You want to extract and alphabetize the list elements.&amp;nbsp; You can do this in a single data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say no list is expected to have more than 25 members, then you can manage with a 25-element arrays of character variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input @1 id  @3 symptoms $ 3-100;
cards;
1 Dizziness/vertigo (NR),Vomitting (NR),Confusion (R)
2 Headache (R),Muscle weakness (R),Acidosis
3 Confusion (R)
4 Vomitting (NR),Headache (R)
run; 

data want (drop=_s _t);
  set have;
  array symptom {25} $30 ;

  do _s=1 to dim(symptom) until (_s=countw(symptoms,','));
    symptom{_s}=strip(scan(symptoms,_s, ','));
  end;
  call sortc(of symptom{*});

  length _alphabetized_symptoms $800;   *For temporary sorted CSV list of symptoms *;
  _alphabetized_symptoms=catx(',',of symptom{*});

  call missing(of symptom{*});
  do _t=1 to _s;
    symptom{_t}=scan(_alphabetized_symptoms,_t,',');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A possible alternative to above, which shifts the sorted values to the left, is to add elements that will always sort higher than actual data, namely assign unneeded elements with hexadecimal 'FF' values.&amp;nbsp; After sorting reset them to blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_s _t);
  set have;
  array symptom {25} $30 ;

  do _s=1 to dim(symptom) until (_s=countw(symptoms,','));
    symptom{_s}=strip(scan(symptoms,_s, ','));
  end;
  if _s&amp;lt;dim(symptom) then do _t=_s+1 to dim(symptom);
    symptom{_t}='FF'x;
  end;

  call sortc(of symptom{*});

  if _s&amp;lt;dim(symptom) then do _t=_s+1 to dim(symptom);
    symptom{_t}=' ';
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 03:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-separate-out-a-column-then-arrange-alphabetically-with/m-p/898052#M354951</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-10-11T03:44:12Z</dc:date>
    </item>
  </channel>
</rss>

