<?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 How do loop through a list? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883879#M349181</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on CVD outcome based on ICD10. The database I have consists of patients with all kinds of diseases. Therefore, I need to find out who has CVD in the database. I was thinking to use "DO" loop. My idea is that if the OBS contains the ICD10 code for CVD then I will keep this OBS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this is 5 OBS of the database. (ID: patient id; icd1-icd5 were the diseases reported by the patients. Patients could have more than one disease.)&lt;/P&gt;&lt;PRE&gt;data cvd;
	input id icd1$ icd2$ icd3$ icd4$ icd5$;
	datalines;
	1 K509 K523 K529 M241 .
	2 A101 I210 K509 M050 I212
	3 B310 K523 I051 . .
	4 H100 H200 I607 I639 I501
	5 I210 I211 I212 I213 .
	RUN;

DATA CVDTRY;
	SET cvd;
	ARRAY TOTALCVD icd1 icd2 icd3 icd4 icd5;
	DO i = 'I210', 'I211', 'I212', 'I213', 'I214', 'I219', 'I051', 'I607';
	IF TOTALCVD[i] = [i] THEN OUTPUT;
END;&lt;/PRE&gt;&lt;P&gt;The log I got was:&lt;/P&gt;&lt;PRE&gt;ERROR: Undeclared array referenced: NAME.
ERROR: Variable NAME has not been declared as an array.
ERROR 22-322: Syntax error, expecting one of the following: a name, INPUT, PUT.&lt;/PRE&gt;&lt;P&gt;I was not sure it is appropriate to use this method, or are there any other approaches to solve problems like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2023 02:47:25 GMT</pubDate>
    <dc:creator>Vergriffenego</dc:creator>
    <dc:date>2023-07-07T02:47:25Z</dc:date>
    <item>
      <title>How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883879#M349181</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on CVD outcome based on ICD10. The database I have consists of patients with all kinds of diseases. Therefore, I need to find out who has CVD in the database. I was thinking to use "DO" loop. My idea is that if the OBS contains the ICD10 code for CVD then I will keep this OBS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this is 5 OBS of the database. (ID: patient id; icd1-icd5 were the diseases reported by the patients. Patients could have more than one disease.)&lt;/P&gt;&lt;PRE&gt;data cvd;
	input id icd1$ icd2$ icd3$ icd4$ icd5$;
	datalines;
	1 K509 K523 K529 M241 .
	2 A101 I210 K509 M050 I212
	3 B310 K523 I051 . .
	4 H100 H200 I607 I639 I501
	5 I210 I211 I212 I213 .
	RUN;

DATA CVDTRY;
	SET cvd;
	ARRAY TOTALCVD icd1 icd2 icd3 icd4 icd5;
	DO i = 'I210', 'I211', 'I212', 'I213', 'I214', 'I219', 'I051', 'I607';
	IF TOTALCVD[i] = [i] THEN OUTPUT;
END;&lt;/PRE&gt;&lt;P&gt;The log I got was:&lt;/P&gt;&lt;PRE&gt;ERROR: Undeclared array referenced: NAME.
ERROR: Variable NAME has not been declared as an array.
ERROR 22-322: Syntax error, expecting one of the following: a name, INPUT, PUT.&lt;/PRE&gt;&lt;P&gt;I was not sure it is appropriate to use this method, or are there any other approaches to solve problems like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 02:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883879#M349181</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-07-07T02:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883880#M349182</link>
      <description>&lt;P&gt;The index into an array has to be an integer, not a character string:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cvdtry;
set cvd;
array totalcvd {*} icd1-icd5;
do i = 1 to fim(totalcvd);
  if totalcvd{i} in ('I210','I211','I212','I213','I214','I219','I051','I607')
  then do;
    icd = totalcvd{i};
    output;
  end;
end;
keep id icd;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you transpose to long:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=cvd 
  out=cvdtry (
    drop=_name_ 
    rename=(col1=icd)
    where=(icd in ('I210','I211','I212','I213','I214','I219','I051','I607'))
  )
;
by id;
var icd:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2023 03:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883880#M349182</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-07T03:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883882#M349184</link>
      <description>&lt;P&gt;Dear Mr. Bremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the solution! The second one works well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first solution, there seemed some problems with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After I ran it, the log reported me with:&lt;/P&gt;&lt;LI-SPOILER&gt;649 do i = 1 to fim(totalcvd);&lt;BR /&gt;---&lt;BR /&gt;68&lt;BR /&gt;ERROR: Illegal reference to the array totalcvd.&lt;BR /&gt;ERROR 68-185: The function FIM is unknown, or cannot be accessed.&lt;/LI-SPOILER&gt;&lt;P&gt;Is "fim" a typo? I also searched online, and did not find a similar word.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 03:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883882#M349184</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-07-07T03:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883884#M349186</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;do i = 1 to fim(totalcvd);&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this should be the SAS function DIM.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 03:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883884#M349186</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-07-07T03:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883885#M349187</link>
      <description>Thanks a lot Kiwi! It is DIM. And I was also trying to just put the numbers of icds. I got the same result. This is really amazing!</description>
      <pubDate>Fri, 07 Jul 2023 03:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883885#M349187</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-07-07T03:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883887#M349188</link>
      <description>&lt;P&gt;That's a "tablet typo". "f" is right next to "d".&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 05:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883887#M349188</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-07T05:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do loop through a list?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883892#M349192</link>
      <description>Sure! Thanks a lot! It works very well!</description>
      <pubDate>Fri, 07 Jul 2023 06:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-loop-through-a-list/m-p/883892#M349192</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-07-07T06:46:59Z</dc:date>
    </item>
  </channel>
</rss>

