<?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: How to align the text characters in SAS output so that each column has same-type value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339156#M77363</link>
    <description>&lt;P&gt;You can create format of poosible diagnosys in desired order, like next code.&lt;/P&gt;
&lt;P&gt;Be careful witt case and typos if need.&lt;/P&gt;
&lt;PRE&gt;proc format lib=work;&lt;BR /&gt; value $diag&lt;BR /&gt; 'eating disorder' = '01'&lt;BR /&gt; 'sleeping disorder' = '02'&lt;BR /&gt; 'seizure' = '03'&lt;BR /&gt; 'lung problem' = '05'&lt;BR /&gt; 'depression' = '06'&lt;BR /&gt; 'panic attack' = '07'&lt;BR /&gt; 'anxiety' = '08'&lt;BR /&gt; ; /* add more lines as mutch as need in desired order */&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input ID AGE DIAGNOSIS $char100.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack&lt;BR /&gt;2 33 lung problem/depression/eating disorder/anxiety/seizure&lt;BR /&gt;3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; length diag diag1-diag8 $20;&lt;BR /&gt; array di $ diag1-diag8;&lt;BR /&gt; n = countw(DIAGNOSIS,'/,'); &lt;BR /&gt; do i=1 to n;&lt;BR /&gt; diag = scan(DIAGNOSIS,i,'/,');&lt;BR /&gt; j=input(put(diag,$diag2.),2.);&lt;BR /&gt; di(j) = diag;&lt;BR /&gt; end; &lt;BR /&gt; drop i j n diag;&lt;BR /&gt;run; &lt;BR /&gt;  &lt;/PRE&gt;
&lt;P&gt;You may get array subscript error&amp;nbsp;in case of diagnosys not defined in the format.&lt;/P&gt;
&lt;P&gt;Just add it to the format, addapt array length and rerun.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Mar 2017 17:30:40 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-03-08T17:30:40Z</dc:date>
    <item>
      <title>How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339057#M77328</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I know how to split text column (DIAGNOSIS) into separate columns (i.e., col1--col4), shown below in&amp;nbsp;SAS output:&lt;/P&gt;
&lt;P&gt;(code in DATA step)&lt;/P&gt;
&lt;P&gt;DIAGNOSIS= TRIM(DIAGNOSIS);&lt;BR /&gt;col1=scan(DIAGNOSIS, 1, '/' || ',');&lt;BR /&gt;col2=scan(DIAGNOSIS, 2, '/' || ',');&lt;BR /&gt;col3=scan(DIAGNOSIS, 3, '/' || ',');&lt;BR /&gt;col4=scan(DIAGNOSIS, 4, '/' || ',');&lt;BR /&gt;col5=scan(DIAGNOSIS, 5, '/' || ',');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7604i7592DB73433699DE/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="sas output.PNG" title="sas output.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;but this is not preferrable.&amp;nbsp;I want the output being like the below, each column having same-type value.&lt;/P&gt;
&lt;P&gt;(The following is preferred SAS output)&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7605iFF1805D6E2D04CE2/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="want output.PNG" title="want output.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how can I do it in SAS? Thanks a lot.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 23:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339057#M77328</guid>
      <dc:creator>lifelearner2015</dc:creator>
      <dc:date>2017-03-07T23:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339059#M77329</link>
      <description>&lt;P&gt;How many possible different diagnosis can you have? I can see that getting wide very fast.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easies method in SAS is to transpose to a long format and then back to a wide format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transpose using an output statement - add output; after each col calculation you've shown.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 23:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339059#M77329</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-07T23:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339060#M77330</link>
      <description>&lt;P&gt;hi, Reeza,&lt;/P&gt;
&lt;P&gt;Thank you for your idea. It's about 8 diagnoses. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 00:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339060#M77330</guid>
      <dc:creator>lifelearner2015</dc:creator>
      <dc:date>2017-03-08T00:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339061#M77331</link>
      <description>&lt;P&gt;Post some sample data, in an easy to import format (datalines preferable) and someone can demonstrate the code if you need help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transpose is the most dynamic solution but probably more steps than a manual solution. If you only have 8, an array with a lookup is also an option, but if you expand the number it can get ugly fast. Plus with the transpose you don't have to worry about the amount or names, it updates automatically.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 00:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339061#M77331</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-08T00:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339064#M77332</link>
      <description>&lt;P&gt;Hi, Reeza,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The simplified original data is like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data diag;&lt;/P&gt;
&lt;P&gt;input ID$ AGE DIAGNOSIS$;&lt;/P&gt;
&lt;P&gt;DATALINES;&lt;/P&gt;
&lt;P&gt;1 22&amp;nbsp;&lt;SPAN&gt;eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2 33 lung&amp;nbsp;&lt;SPAN&gt;problem/depression/eating disorder/anxiety/seizure&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 00:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339064#M77332</guid>
      <dc:creator>lifelearner2015</dc:creator>
      <dc:date>2017-03-08T00:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339090#M77340</link>
      <description>&lt;P&gt;There are multiple ways of doing this, but the main issues are this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* Your diagnoses are formatted in one long string, with a delimiter separating each diagnosis&lt;/P&gt;&lt;P&gt;(Next time get your data manager to format the data as one row per diagnosis, IMO that would be a better data model)&lt;/P&gt;&lt;P&gt;* You need to get a distinct list of diagnoses across your entire dataset&lt;/P&gt;&lt;P&gt;* The count of distinct diagnoses determines the number of columns to create in your output dataset&lt;/P&gt;&lt;P&gt;* You would like the diagnosis values to "line up" in each column, in alphabetical order&lt;/P&gt;&lt;P&gt;* You want the code to "just work" if the number of distinct diagnoses changes in the future (or you want to apply this same approach to a different study).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are a few approaches, pick your favourite, apologies for the length and repeated code, it's just a cut-and-paste from my EG session...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Double array approach:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID AGE DIAGNOSIS $char100.;
DATALINES;
1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack
2 33 lung problem/depression/eating disorder/anxiety/seizure
3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder
;
run;

* data step transpose of diagnosis ;
data diagnoses;
   set have;
   length diag $100;
   do i=1 to countw(diagnosis,"/");
      diag=scan(diagnosis,i,"/");
      output;
   end;
   drop diagnosis i;
run;

* get distinct list of diagnoses ;
proc sort data=diagnoses (keep=diag) out=diags nodupkey;
   by diag;
run;

* get count of diagnoses ;
data _null_;
   set diags nobs=nobs;
   call symputx("nobs",nobs,"G");
   stop;
run;

* use two arrays ;
data want;
   * load an array of the distinct list of diagnoses ;
   array diags[&amp;amp;nobs] $100 _temporary_;
   do until (eof1);
      set diags end=eof1;
      diags[_n_]=diag;
      _n_+1;
   end;

   * now process the main dataset ;
   do until (eof2);
      set diagnoses end=eof2;
      by id age;
      length diagnosis1-diagnosis&amp;amp;nobs $100;
      array diagnosis[&amp;amp;nobs] diagnosis:;
      if first.id then call missing(of diagnosis:);
      do _n_=1 to dim(diags);
         if diag=diags[_n_] then diagnosis[_n_]=diag;
      end;
      if last.id then output;
   end;
   keep id age diagnosis:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hash object approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID AGE DIAGNOSIS $char100.;
DATALINES;
1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack
2 33 lung problem/depression/eating disorder/anxiety/seizure
3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder
;
run;

* data step transpose of diagnosis ;
data diagnoses;
   set have;
   length diag $100;
   do i=1 to countw(diagnosis,"/");
      diag=scan(diagnosis,i,"/");
      output;
   end;
   drop diagnosis i;
run;

* get distinct list of diagnoses ;
proc sort data=diagnoses (keep=diag) out=diags nodupkey;
   by diag;
run;

* store the index with the list ;
data diags;
   set diags end=eof;
   index+1;
   if eof then call symputx("nobs",index,"G");
run;

* use a hash object ;
data want;
   if 0 then set diags;  * sets column attributes ;
   if (_n_=1) then do;
      declare hash h (dataset:"diags");
      h.defineKey("diag");
      h.defineData("index");
      h.defineDone();
   end;
   call missing(of _all_);  * implied retain on "if 0 then set diags" statement ;

   do until (last.id);
      set diagnoses; * this will read in id age diag ;
      by id age;

      * declare the diagnosis columns ;
      length diagnosis1-diagnosis&amp;amp;nobs $100;
      array diagnosis[*] diagnosis:;

      * find the matching diagnosis in the hash ;
      * this will set the array pointer value ;
      h.find();

      * now assign the value to the correct array element ;
      diagnosis[index]=diag;
   end;
   output;
   keep id age diagnosis:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Interleave data approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID AGE DIAGNOSIS $char100.;
DATALINES;
1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack
2 33 lung problem/depression/eating disorder/anxiety/seizure
3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder
;
run;

* data step transpose of diagnosis ;
data diagnoses;
   set have;
   length diag $100;
   do i=1 to countw(diagnosis,"/");
      diag=scan(diagnosis,i,"/");
      output;
   end;
   drop diagnosis i;
run;

* get distinct list of diagnoses ;
proc sort data=diagnoses (keep=diag) out=diags nodupkey;
   by diag;
run;

* get count ;
data _null_;
   set diags nobs=nobs;
   call symputx("nobs",nobs,"G");
   stop;
run;

* transpose the list ;
proc transpose data=diags out=diags_trans (keep=col:);
   var diag;
run;

* join with the diagnoses dataset and derive results ;
data want;
   format id age;  * set partial PDV order ;
   if (_n_=1) then set diags_trans;
   do until (last.id);
      set diagnoses;
      by id age;
      length diagnosis1-diagnosis&amp;amp;nobs $100;
      array diagnosis[*] diagnosis:;
      array col[*] col:;
      do i=1 to dim(col);
         if diag=col[i] then do;
            diagnosis[i]=diag;
            leave;
         end;
      end;
   end;
   output;
   keep id age diagnosis:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cartesian product approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID AGE DIAGNOSIS $char100.;
DATALINES;
1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack
2 33 lung problem/depression/eating disorder/anxiety/seizure
3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder
;
run;

* data step transpose of diagnosis ;
data diagnoses;
   set have;
   length diag $100;
   do i=1 to countw(diagnosis,"/");
      diag=scan(diagnosis,i,"/");
      output;
   end;
   drop diagnosis i;
run;

* get distinct list of diagnoses ;
proc sort data=diagnoses (keep=diag) out=diags nodupkey;
   by diag;
run;

* store the index with the list ;
data diags;
   set diags end=eof;
   index+1;
   if eof then call symputx("nobs",index,"G");
run;

* create the Cartesian product of the diagnoses, which will set the column index ;
* Note: this could perform badly if the data is really large ;
proc sql;
   create table temp as
   select a.id, a.age,a.diag,b.index
   from diagnoses a
   full join
   diags b
   on a.diag=b.diag
   order by id, age;
quit;

* now use the index to line up the columns ;
data want;
   do until (last.id);
      set temp;
      by id age;
      length diagnosis1-diagnosis&amp;amp;nobs $100;
      array diagnosis[*] diagnosis:;
      diagnosis[index]=diag;
   end;
   output;
   keep id age diagnosis:;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 04:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339090#M77340</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2017-03-08T04:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339156#M77363</link>
      <description>&lt;P&gt;You can create format of poosible diagnosys in desired order, like next code.&lt;/P&gt;
&lt;P&gt;Be careful witt case and typos if need.&lt;/P&gt;
&lt;PRE&gt;proc format lib=work;&lt;BR /&gt; value $diag&lt;BR /&gt; 'eating disorder' = '01'&lt;BR /&gt; 'sleeping disorder' = '02'&lt;BR /&gt; 'seizure' = '03'&lt;BR /&gt; 'lung problem' = '05'&lt;BR /&gt; 'depression' = '06'&lt;BR /&gt; 'panic attack' = '07'&lt;BR /&gt; 'anxiety' = '08'&lt;BR /&gt; ; /* add more lines as mutch as need in desired order */&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input ID AGE DIAGNOSIS $char100.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack&lt;BR /&gt;2 33 lung problem/depression/eating disorder/anxiety/seizure&lt;BR /&gt;3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; length diag diag1-diag8 $20;&lt;BR /&gt; array di $ diag1-diag8;&lt;BR /&gt; n = countw(DIAGNOSIS,'/,'); &lt;BR /&gt; do i=1 to n;&lt;BR /&gt; diag = scan(DIAGNOSIS,i,'/,');&lt;BR /&gt; j=input(put(diag,$diag2.),2.);&lt;BR /&gt; di(j) = diag;&lt;BR /&gt; end; &lt;BR /&gt; drop i j n diag;&lt;BR /&gt;run; &lt;BR /&gt;  &lt;/PRE&gt;
&lt;P&gt;You may get array subscript error&amp;nbsp;in case of diagnosys not defined in the format.&lt;/P&gt;
&lt;P&gt;Just add it to the format, addapt array length and rerun.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 17:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339156#M77363</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-08T17:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339512#M77454</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;, these are great ideas&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;! &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using a format to derive the column pointer, plus parsing the original table in place, results in tighter and easier to read code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would make these&amp;nbsp;minor changes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since a format:&lt;/P&gt;&lt;P&gt;* always returns character output&lt;/P&gt;&lt;P&gt;* can accept either a numeric or character input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and an informat:&lt;/P&gt;&lt;P&gt;* always takes character input&lt;/P&gt;&lt;P&gt;* can return either a numeric or character output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can use a numeric informat instead of a character format. &amp;nbsp;This simplifies the code to a single call to input instead of the double input(put(...)) construct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd make this data driven instead of hard coded, in case the list of diagnoses changes in the future, or the code is to be reused in another study.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my latest iteration...thanks for the great ideas!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID AGE DIAGNOSIS $char100.;
DATALINES;
1 22 eating disorder/sleeping disorder/seizure/lung problem/depression/panic attack
2 33 lung problem/depression/eating disorder/anxiety/seizure
3 44 sleeping disorder/panic attack/anxiety/lung problem/eating disorder
;
run;

* data step transpose of diagnosis ;
* a view may perform better if the source file is large ;
* since disk I/O is reduced ;
data diagnoses / view=diagnoses;
   set have (rename=(diagnosis=temp));
   length diagnosis $100;
   do i=1 to countw(temp,"/");
      diagnosis=scan(temp,i,"/");
      output;
   end;
   keep diagnosis;
run;

* get distinct list of diagnoses ;
proc sort data=diagnoses out=diagnosis nodupkey;
   by diagnosis;
run;

* create a cntlin dataset for proc format ;
* we want to create a numeric informat ;
data cntlin;
   format fmtname type start end label;  * PDV order ;
   keep fmtname type start end label;
   set diagnosis end=eof;
   fmtname='diagnosis';
   type='I';
   start=diagnosis;
   end=start;
   label+1;
   if eof then call symputx("n",label,"G");
run;

* create informat ;
proc format cntlin=cntlin;
run;

* create the desired output ;
data want;
   set have (rename=(diagnosis=temp));
   length diagnosis diagnosis1-diagnosis&amp;amp;n $100;
   array arrdiags[*] diagnosis1-diagnosis&amp;amp;n;
   do i=1 to countw(temp,"/");
      diagnosis=scan(temp,i,"/");
      arrdiags[input(diagnosis,diagnosis.)]=diagnosis;
   end;
   keep id age diagnosis1-diagnosis&amp;amp;n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 02:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339512#M77454</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2017-03-09T02:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339540#M77464</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;, I like the idea of informat instead of the format.&lt;/P&gt;
&lt;P&gt;I have thought of using cntlout in oreder to create the full list and count them,&lt;/P&gt;
&lt;P&gt;but there may be some isuues:&lt;/P&gt;
&lt;P&gt;- &lt;STRONG&gt;case&lt;/STRONG&gt; letters. Diagnoses shold be all either lowcase or uppercase&lt;/P&gt;
&lt;P&gt;- &lt;STRONG&gt;typos&lt;/STRONG&gt; - should be handeled manually to avoid semi-duplicates/splitting.&lt;/P&gt;
&lt;P&gt;- as mutch as I know the&amp;nbsp;&lt;STRONG&gt;START, END&lt;/STRONG&gt; variables in a format are limited &lt;STRONG&gt;length&lt;/STRONG&gt;. Is it still 16 Characters ?&lt;BR /&gt;&amp;nbsp; how to deal with diagnosis that are longer ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60193"&gt;@lifelearner2015&lt;/a&gt;, check, do you have any of above issues ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;- case&lt;/STRONG&gt; is the easiest to deal by using sas function lowcase() or upcase() - whatever you preffer.&lt;/P&gt;
&lt;P&gt;- you won't find typos if diagnoses are selected from a fixed list and not by typing.&lt;BR /&gt;&amp;nbsp; you can look for typos in the sorted cntlout dataset.&lt;/P&gt;
&lt;P&gt;- is there any diagnosys length greater than 16 characters ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 04:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339540#M77464</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-09T04:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339547#M77470</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;, I like the idea of informat instead of the format.&lt;/P&gt;&lt;P&gt;I have thought of using cntlout in oreder to create the full list and count them,&lt;/P&gt;&lt;P&gt;but there may be some isuues:&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;case&lt;/STRONG&gt; letters. Diagnoses shold be all either lowcase or uppercase&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SB: The input function does a case-sensitive comparision to the format value. If a case-insenstive comparison is desired, the UPCASE informat option could be used. See &lt;A href="http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1pmw90bl3jzgdn1w4202kclxtho.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1pmw90bl3jzgdn1w4202kclxtho.htm&lt;/A&gt;. I haven't investigated how to specify UPCASE in an cntlin dataset; reverse engineering a cntlout dataset would probably show how this is done (or the doc).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- &lt;STRONG&gt;typos&lt;/STRONG&gt; - should be handeled manually to avoid semi-duplicates/splitting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SB: I'm assuming the source data is clean. If there are typos then the typos will be matched, since the informat is &lt;U&gt;exactly derived&lt;/U&gt; from the source data. Otherwise &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60193"&gt;@lifelearner2015&lt;/a&gt;&amp;nbsp;will need to clean his data first before creating the informat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- as mutch as I know the&amp;nbsp;&lt;STRONG&gt;START, END&lt;/STRONG&gt; variables in a format are limited &lt;STRONG&gt;length&lt;/STRONG&gt;. Is it still 16 Characters ?&lt;BR /&gt;&amp;nbsp; how to deal with diagnosis that are longer ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SB: See test code below.&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60193"&gt;@lifelearner2015&lt;/a&gt;, check, do you have any of above issues ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- case&lt;/STRONG&gt; is the easiest to deal by using sas function lowcase() or upcase() - whatever you preffer.&lt;/P&gt;&lt;P&gt;- you won't find typos if diagnoses are selected from a fixed list and not by typing.&lt;BR /&gt;&amp;nbsp; you can look for typos in the sorted cntlout dataset.&lt;/P&gt;&lt;P&gt;- is there any diagnosys length greater than 16 characters ?&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran this test code. &amp;nbsp;It seemed to work for me. &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60193"&gt;@lifelearner2015&lt;/a&gt;, use which ever approach you prefer, or try them all as a learning exercise. &amp;nbsp;Post any further issues as a follow up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   length long $1000;
   char="ABCDEFGHIJKLmnopqrstuvwxyz";
   long=repeat(char,100);
run;
data cntlin;
   set test (keep=long);
   start=long;
   end=start;
   label=1;
   fmtname="test";
   type="I";
run;
proc format cntlin=cntlin;
run;
data test2;
   set test;
   test1=input(long,test.);
   test2=input(substr(long,1,999),test.);  * does not match, so char[1000] is signficant ;
   test3=input(upcase(long),test.);  * does not match, so case is significant ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2017 06:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339547#M77470</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2017-03-09T06:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to align the text characters in SAS output so that each column has same-type value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339708#M77525</link>
      <description>&lt;P&gt;I have found some options running proc format.&lt;/P&gt;
&lt;P&gt;Next was copied from an O/L documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Syntax&lt;/U&gt;&lt;/STRONG&gt;:&amp;nbsp;&lt;!-- &amp;lt;meta prod="Base SAS 9.2 Procedures Guide" title="PROC FORMAT Statement" url="../proc.hlp/a002473464.htm "&gt; --&gt;&lt;/P&gt;
&lt;DIV class="sgml"&gt;
&lt;TABLE cellspacing="2" cellpadding="4"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD&gt;&lt;SPAN class="strong"&gt;PROC FORMAT&lt;/SPAN&gt; &amp;lt;&lt;SPAN class="emph"&gt;option(s)&lt;/SPAN&gt;&amp;gt;;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Relevant options to issues&lt;/STRONG&gt;&lt;/U&gt;:&lt;BR /&gt;&lt;!-- &amp;lt;meta prod="Base SAS 9.2 Procedures Guide" title="PROC FORMAT Statement" url="../proc.hlp/a002473464.htm "&gt; --&gt;&lt;/P&gt;
&lt;DIV class="sgml"&gt;
&lt;DL&gt;
&lt;DT&gt;&lt;SPAN class="strong"&gt;&lt;STRONG&gt;MAXLABLEN&lt;/STRONG&gt;=&lt;SPAN class="strongEmph"&gt;number-of-characters&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;specifies the number of characters in the informatted or formatted value that you want to appear in the CNTLOUT= data set or in the output of the FMTLIB option. The FMTLIB option&lt;STRONG&gt; prints a maximum of 40 characters&lt;/STRONG&gt; for the informatted or formatted value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DD&gt;
&lt;DT&gt;&lt;SPAN class="strong"&gt;&lt;STRONG&gt;MAXSELEN&lt;/STRONG&gt;=&lt;SPAN class="strongEmph"&gt;number-of-characters&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;specifies the number of characters in the start and end values that you want to appear in the CNTLOUT= data set or in the output of the FMTLIB option. The FMTLIB option &lt;STRONG&gt;prints a maximum of 16 characters&lt;/STRONG&gt; for start and end values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;!-- &amp;lt;meta prod="Base SAS 9.2 Procedures Guide" title="PROC FORMAT Statement" url="../proc.hlp/a002473464.htm "&gt; --&gt;&lt;/P&gt;
&lt;DIV class="sgml"&gt;
&lt;DL&gt;
&lt;DT&gt;&lt;STRONG&gt;&lt;SPAN class="strong"&gt;FMTLIB&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;prints information about all the informats and formats in the catalog that is specified in the LIBRARY= option. To get information only about specific informats or formats, subset the catalog using the SELECT or EXCLUDE statement.&lt;/P&gt;
&lt;TABLE cellspacing="2" cellpadding="4"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD width="95" align="left" class="label"&gt;Interaction:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockLight"&gt;The PAGE option invokes FMTLIB.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD width="95" align="left" class="label"&gt;Tip:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockLight"&gt;If your output from FMTLIB is not formatted correctly, then try increasing the value of the LINESIZE= system option.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top"&gt;
&lt;TD width="95" align="left" class="label"&gt;Tip:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockLight"&gt;If you use the SELECT or EXCLUDE statement and omit the FMTLIB and CNTLOUT= options, then the procedure invokes the FMTLIB option and you receive FMTLIB option output.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Relating to CASE issue - next is proposed code copied from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15043"&gt;@ScottBass&lt;/a&gt;&amp;nbsp;example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
   set test (keep=long);
   start=upcase(long);    /* &amp;lt;&amp;lt;&amp;lt;&amp;lt; upcase function added */
   end=start;
   label=1;
   fmtname="test";
   type="I";
run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; cntlin&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;cntlin&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; test&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;   long = upcase(long); /* &amp;lt;&amp;lt;&amp;lt; line added to enable upper case comparison */   
   test1&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;long&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;test&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   test2&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;substr&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;long&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;999&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;test&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;  &lt;SPAN class="token comment"&gt;* does not match, so char[1000] is signficant ;&lt;/SPAN&gt;
   test3&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;upcase&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;long&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;test&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;  &lt;SPAN class="token comment"&gt;* does not match, so case is significant ;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DD&gt;
&lt;/DL&gt;
&lt;/DIV&gt;
&lt;/DD&gt;
&lt;/DL&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Mar 2017 17:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-the-text-characters-in-SAS-output-so-that-each/m-p/339708#M77525</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-09T17:13:57Z</dc:date>
    </item>
  </channel>
</rss>

