<?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: using arrays and do loop to get frequency in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772611#M31097</link>
    <description>&lt;P&gt;I understand better now, thanks. It created a new variable called diagnosis for me which I can output. But pardon me, i'm new in SAS and i still dont fully understand the array and do loop concept. Is the diagnosis variable showing the observations common to the variables in my array? thats what i really need, the most frequent observations in the 10 variables in my array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data week6.question4;
set week6.THCICSamp;
array diag (10) $ admitting_diag princ_diag_code oth_diag_code_1 - oth_diag_code_8;
do i = 1 to 10;
diagnosis = diag (i);
end;
run;
proc freq data = week6.question4 order=freq;
tables diagnosis / out = week6.ques4freq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="the observations in diagnosis are codes for disease types , present in the different variables in my array" style="width: 796px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64432i5D9B052930CD6CF8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (683).png" alt="the observations in diagnosis are codes for disease types , present in the different variables in my array" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;the observations in diagnosis are codes for disease types , present in the different variables in my array&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Oct 2021 01:50:55 GMT</pubDate>
    <dc:creator>Banke</dc:creator>
    <dc:date>2021-10-07T01:50:55Z</dc:date>
    <item>
      <title>using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772336#M31060</link>
      <description>&lt;P&gt;I am required to check 5 variables (all diagnosis) to find out the 5 most occuring diagnosis and average length of stay in hospital which is another variable. I tried this for the 1st part ( frequency) and it didnt work,it instead multiplied my observations by 10. how can i fix this please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA WEEK6.QUESTION4;&lt;BR /&gt;SET WEEK6.THCICSAMP;&lt;BR /&gt;ARRAY DIAG (10) ADMITTING_DIAG PRINC_DIAG_CODE OTH_DIAG_CODE_1 - OTH_DIAG_CODE_8;&lt;BR /&gt;DO I = 1 TO 10;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;END;&lt;BR /&gt;PROC FREQ DATA = WEEK6.QUESTION4;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 04:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772336#M31060</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-06T04:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772348#M31062</link>
      <description>&lt;P&gt;Please post data in usable form along with the expected result. And please don't write code all upcase, this is hardly readable and post code using "Insert SAS code".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 05:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772348#M31062</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-06T05:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772401#M31072</link>
      <description>&lt;P&gt;In addition to the comments from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt; (which you should ALWAYS do, that's ALWAYS, every single time, even if we don't ask)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use a DO loop with an array, you have to assign a value to a variable, I think what you want inside the do loop is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;diagnosis = diag(i);
output;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Oct 2021 11:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772401#M31072</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-06T11:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772418#M31073</link>
      <description>&lt;P&gt;I don't quite understand what you mean by 'in a useable form and 'expected results' . I hope this does it:&amp;nbsp; I am asked to get the most common 5 diagnoses in my variables listed in my array command, and the mean length of stay (another variable) of those diagnoses. They are variables showing&amp;nbsp; diagnosis of patients at different times. so i am thinking to output only those variables i need and get their frequencies. I will then get their means.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i am getting in my log is :&amp;nbsp;&lt;/P&gt;
&lt;DIV id="sasLogNote1_1633526018657" class="sasNote"&gt;&lt;FONT size="2"&gt;There were 9056 observations read from the data set WEEK6.THCICSAMP.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1633526018657" class="sasNote"&gt;&lt;FONT size="2"&gt;NOTE: The data set WEEK6.QUESTION4 has 90560 observations and 108 variables.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1633526018657" class="sasNote"&gt;&lt;FONT size="2"&gt;NOTE: DATA statement used (Total process time):&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&lt;FONT size="2"&gt;real time 0.05 seconds&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&lt;FONT size="2"&gt;cpu time 0.06 seconds&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&lt;FONT size="2"&gt;my observations have been multiplied by 10&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data week6.question4;
set week6.THCICSamp;
array diag (10) $ admitting_diag princ_diag_code oth_diag_code_1 - oth_diag_code_8;
do i = 1 to 10;
diagnosis = diag (i);
output;
end;
proc freq data = week6.question4 order=freq;
tables _ALL_ / out = week6.ques4freq;
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, 06 Oct 2021 13:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772418#M31073</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-06T13:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772420#M31074</link>
      <description>&lt;P&gt;Yes, your observations have been multiplied by 10. Why? Because the OUTPUT statement in the DO loop executes 10 times for each record in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in PROC FREQ, you want to use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tables diagnosis/out=week6.ques4freq;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Data in usable form — here are instructions: &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 13:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772420#M31074</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-06T13:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772611#M31097</link>
      <description>&lt;P&gt;I understand better now, thanks. It created a new variable called diagnosis for me which I can output. But pardon me, i'm new in SAS and i still dont fully understand the array and do loop concept. Is the diagnosis variable showing the observations common to the variables in my array? thats what i really need, the most frequent observations in the 10 variables in my array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data week6.question4;
set week6.THCICSamp;
array diag (10) $ admitting_diag princ_diag_code oth_diag_code_1 - oth_diag_code_8;
do i = 1 to 10;
diagnosis = diag (i);
end;
run;
proc freq data = week6.question4 order=freq;
tables diagnosis / out = week6.ques4freq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="the observations in diagnosis are codes for disease types , present in the different variables in my array" style="width: 796px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64432i5D9B052930CD6CF8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (683).png" alt="the observations in diagnosis are codes for disease types , present in the different variables in my array" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;the observations in diagnosis are codes for disease types , present in the different variables in my array&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 01:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772611#M31097</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-07T01:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772628#M31098</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/394970"&gt;@Banke&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I understand better now, thanks. It created a new variable called diagnosis for me which I can output. But pardon me, i'm new in SAS and i still dont fully understand the array and do loop concept. Is the diagnosis variable showing the observations common to the variables in my array? thats what i really need, &lt;FONT color="#FF6600"&gt;the most frequent observations in the 10 variables in my array.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have no idea what you expect as result. I&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b" data-language-for-alternatives="en" data-language-to-translate-into="de" data-phrase-index="0"&gt;&lt;SPAN&gt;t would be much easier to help you if you showed your data&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; and the expected result. In your initial post, you said:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;am required to check 5 variables (all diagnosis) to find out the 5 most occurring diagnosis&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is exactly the result of proc freq, the five most occurring diagnosis are the first five lines in the result.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 04:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772628#M31098</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-07T04:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772666#M31099</link>
      <description>&lt;P&gt;We're trying to help you, but you have to help us. We have asked before, and we ask again (although we should not have to ask twice) — show us a portion of your data (following the instructions I gave) and show us the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's nearly impossible to move forward now without this information. Instead of ignoring our requests for information, you will get much faster and better answers by actually providing the information requested.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 10:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772666#M31099</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-07T10:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772736#M31100</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thcic_id is patient no, provider name is hospital they are attending" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64461i224FA5B63FC7B4D0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (688).png" alt="thcic_id is patient no, provider name is hospital they are attending" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;thcic_id is patient no, provider name is hospital they are attending&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="the diagnosis (there are different types , from admitting_diag to oth_diag_code_8" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64462i32A73031CC0183F3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (689).png" alt="the diagnosis (there are different types , from admitting_diag to oth_diag_code_8" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;the diagnosis (there are different types , from admitting_diag to oth_diag_code_8&lt;/span&gt;&lt;/span&gt;Why would I ignore requests when I need help? I have posted my questions in the new sas users forum for a reason; I have barely spent 1 month using sas and it is the first time&amp;nbsp; programming tool I will ever use. I am working with a huge dataset so i cant type out where the information are . I have now attached a screenshot of where the variables are. I didnt really understand the information in the link you shared. the snytax and instructions looked so complex. Desired results? I dont have that, it's an assignment.&amp;nbsp; I have mentioned what I am asked to do twice. Maybe if I post the question, it will provide more clarity. Please take it easy with me, your responses are dampening my zeal. I appreciate the help I get from this forum&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Question&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Using all diagnosis variables (Admitting_Diag, Princ_Diag, Oth_Diag_Code2-Oth_DiagCcode10) recheck the most common five diagnoses; report and update the frequencies and average LOS for those from #3.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772736#M31100</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-07T14:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772756#M31105</link>
      <description>&lt;P&gt;You can just makeup some example data to allow you (and us) to work out by hand what you are trying to do.&lt;/P&gt;
&lt;P&gt;For example you might just retype a few of the lines you see in the data you have.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length los 8 Admitting_Diag  Princ_Diag  Oth_Diag_Code2-Oth_Diag_Code10 $7;
  input los -- Oth_Diag_Code10 ;
cards;
7 64681 79579 66331 66411 . . . . . . .
1 v3001 7746      .     . . . . . . . .
5 v3001    .      .     . . . . . . . .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just make it up from scratch. This is best as then you can create examples that test the boundary conditions of your logic.&amp;nbsp; For example by having the same DX code appear in multiple records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To count the number of times each DX code appears you could either move them all into one variable and count that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall;
  set have;
  array dx Admitting_Diag  Princ_Diag  Oth_Diag_Code2-Oth_Diag_Code10;
  do i=1 to dim(dx);
     dxcode = dx[i];
     if not missing(dxcode) then output;
  end;
  drop i Admitting_Diag  Princ_Diag  Oth_Diag_Code2-Oth_Diag_Code10;
run;
proc freq data=tall order=freq ;
   tables dxcode / noprint out=counts;
run;
proc print data=counts(obs=5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    dxcode    COUNT    PERCENT

 1     v3001       2      28.5714
 2     64681       1      14.2857
 3     66331       1      14.2857
 4     66411       1      14.2857
 5     7746        1      14.2857
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For average LOS you might use PROC MEANS (also known as PROC SUMMARY) this will also generate the frequency.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means noprint nway data=tall;
  class dxcode ;
  var los;
  output out=means mean=mean_los;
run;
proc sort data=means;
  by descending _freq_ ;
run;
proc print data=means (obs=5);
  var dxcode _freq_ mean_los;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    dxcode    _FREQ_    mean_los

 1     v3001        2          3
 2     64681        1          7
 3     66331        1          7
 4     66411        1          7
 5     7746         1          1
&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>Thu, 07 Oct 2021 14:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772756#M31105</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-07T14:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: using arrays and do loop to get frequency</title>
      <link>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772793#M31109</link>
      <description>Thank you so much, I understand better now. I'm sorry for making it difficult to help me. I honestly could not interpret the terminologies correctly.&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Oct 2021 15:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/using-arrays-and-do-loop-to-get-frequency/m-p/772793#M31109</guid>
      <dc:creator>Banke</dc:creator>
      <dc:date>2021-10-07T15:28:03Z</dc:date>
    </item>
  </channel>
</rss>

