<?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 question about array programming in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435975#M108351</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm really struggling to program a few arrays and would love some help!&amp;nbsp; Right now, the data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Comorbidity1&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Comorbidity2&amp;nbsp; Comorbidity3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Diabetes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Heart failure&amp;nbsp; &amp;nbsp; &amp;nbsp;Lung disease&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HTN&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Diabetes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Glaucoma&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; data have;&lt;BR /&gt;array COMORBIDITY [3] COMORBIDITY1-COMORBIDITY3;   
do a=1 to 3;
   if COMORBIDITY [a] &amp;gt; ' ' then do;
      diagnosis = COMORBIDITY[a];
end; end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq order=freq data=want; tables diagnosis; 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;I would like&amp;nbsp;to know the frequency of diagnoses in the cohort of 3 people regardless of whether the diagnosis is sitting in column 1-3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Diabetes 2&lt;/P&gt;&lt;P&gt;HTN 1&lt;/P&gt;&lt;P&gt;Glaucoma 1&lt;/P&gt;&lt;P&gt;Heart failure 1&lt;/P&gt;&lt;P&gt;Lung Disease 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I think I'm just getting the last value...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions are:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;Should I make a new data file called "diagnosis" and use proc transpose to make it into a long format?&lt;/P&gt;&lt;P&gt;2) Should I use syntax _temp_ to make a temporary long file instead of wide?&lt;/P&gt;&lt;P&gt;3)&amp;nbsp;How would an&amp;nbsp;output statement after the "end; end;" change what I get?&lt;/P&gt;&lt;P&gt;4) Should I use proc sql instead of the above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Sat, 10 Feb 2018 19:10:28 GMT</pubDate>
    <dc:creator>lmyers2</dc:creator>
    <dc:date>2018-02-10T19:10:28Z</dc:date>
    <item>
      <title>question about array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435975#M108351</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm really struggling to program a few arrays and would love some help!&amp;nbsp; Right now, the data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Comorbidity1&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Comorbidity2&amp;nbsp; Comorbidity3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Diabetes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Heart failure&amp;nbsp; &amp;nbsp; &amp;nbsp;Lung disease&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HTN&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Diabetes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Glaucoma&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; data have;&lt;BR /&gt;array COMORBIDITY [3] COMORBIDITY1-COMORBIDITY3;   
do a=1 to 3;
   if COMORBIDITY [a] &amp;gt; ' ' then do;
      diagnosis = COMORBIDITY[a];
end; end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq order=freq data=want; tables diagnosis; 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;I would like&amp;nbsp;to know the frequency of diagnoses in the cohort of 3 people regardless of whether the diagnosis is sitting in column 1-3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Diabetes 2&lt;/P&gt;&lt;P&gt;HTN 1&lt;/P&gt;&lt;P&gt;Glaucoma 1&lt;/P&gt;&lt;P&gt;Heart failure 1&lt;/P&gt;&lt;P&gt;Lung Disease 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I think I'm just getting the last value...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My questions are:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;Should I make a new data file called "diagnosis" and use proc transpose to make it into a long format?&lt;/P&gt;&lt;P&gt;2) Should I use syntax _temp_ to make a temporary long file instead of wide?&lt;/P&gt;&lt;P&gt;3)&amp;nbsp;How would an&amp;nbsp;output statement after the "end; end;" change what I get?&lt;/P&gt;&lt;P&gt;4) Should I use proc sql instead of the above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 19:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435975#M108351</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2018-02-10T19:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: question about array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435979#M108353</link>
      <description>&lt;P&gt;Good observation ... you are getting the last value only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5) You should put the OUTPUT statement BEFORE the end; end; so that each nonmissing diagnosis will be output&lt;/P&gt;
&lt;P&gt;6) There should be a SET statement (not two DATA statements)&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 19:33:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435979#M108353</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-10T19:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: question about array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435980#M108354</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input (CaseID     Comorbidity1   Comorbidity2  Comorbidity3) (:$20.);
datalines;
1               Diabetes            Heartfailure     Lungdisease
2               HTN      . .
3               Diabetes            Glaucoma
;

data _have;
set have;
array t(*) Comorbidity:;
do _n_=1 to dim(t);
diagnosis=t(_n_);
output;
end;
run;

proc freq data=_have(where=(not missing(diagnosis)) );
tables diagnosis/out=want(drop=percent);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Feb 2018 19:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435980#M108354</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-10T19:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: question about array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435982#M108356</link>
      <description>&lt;P&gt;or hashes with arrays:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input (CaseID     Comorbidity1   Comorbidity2  Comorbidity3) (:$20.);
datalines;
1               Diabetes            Heartfailure     Lungdisease
2               HTN      . .
3               Diabetes            Glaucoma
;

data _null_;
 if _N_ = 1 then do;
 	length diagnosis $20 count 8;
     declare hash h(ordered:'y' );
     h.defineKey('diagnosis');
     h.defineData('diagnosis','count');
     h.defineDone( );
     call missing(diagnosis, count);
   end;
set have end=last;
array t(*) Comorbidity:;
do _n_=1 to dim(t);
diagnosis=t(_n_);
if h.check() ne 0 then do;count=1;h.add();end;
else if h.find()=0 then do;count=count+1;h.replace();end;
end;
if last then h.output(dataset:'want(where=(not missing(diagnosis)))');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Feb 2018 19:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/435982#M108356</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-10T19:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: question about array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/436012#M108375</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165633"&gt;@lmyers2&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My questions are:&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;Should I make a new data file called "diagnosis" and use proc transpose to make it into a long format?&lt;/P&gt;
&lt;P&gt;2) Should I use syntax _temp_ to make a temporary long file instead of wide?&lt;/P&gt;
&lt;P&gt;3)&amp;nbsp;How would an&amp;nbsp;output statement after the "end; end;" change what I get?&lt;/P&gt;
&lt;P&gt;4) Should I use proc sql instead of the above?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1. Yes, this is better in the long run, but you can transpose via an array or PROC TRANSPOSE&lt;/P&gt;
&lt;P&gt;2. Not necessarily, using a long data is easier in the long run. If you want to know how many patients have X disease, you can use a single line with an IF or WHERE statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. answered by others&lt;/P&gt;
&lt;P&gt;4. No, SQL doesn't work well with wide files either, especially because you can't use arrays or variable lists. Once its a long file, SQL is a valid option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 23:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/question-about-array-programming/m-p/436012#M108375</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-10T23:03:42Z</dc:date>
    </item>
  </channel>
</rss>

