<?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: Retain in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567121#M159444</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236266"&gt;@ChuksManuel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You are right. They are stored as character variables. How do i find out which codes lie between '311' and '31199' in each hospital. I guess i would need to convert the character codes to numeric right? Because i tried running the code in character form and it didn't give me what i was looking for.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Codes between '311' and '31199' will work with clean data.&amp;nbsp; Although I don't think there are any valid codes in that range other than '311'.&amp;nbsp; Also make sure you haven't mistakenly stored codes that start with zero without the leading zero.&amp;nbsp; Otherwise you might include codes that should have started with '031'&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;031 Diseases due to other mycobacteria&lt;/PRE&gt;
&lt;P&gt;Show the data that is causing the trouble. Make a small self contained example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step is just reducing the data to one observation per hospital and id combination. If you want the total per hospital you will still need to count/add them.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2019 02:12:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-06-19T02:12:07Z</dc:date>
    <item>
      <title>Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567100#M159430</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have this dataset w&lt;/SPAN&gt;&lt;SPAN&gt;ith observations sorted by 6 hospitals - 518 546 548 573 672 673.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to determine the number of people within each hospital and overall that have a diagnostic code of '311' through '31199' and i have used the retain function for this.&lt;/P&gt;&lt;P&gt;Here are my codes.&lt;/P&gt;&lt;P&gt;Any help will be appreciated. Data is attached&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data seven; set one;&lt;BR /&gt;by hospital id ;&lt;BR /&gt;retain hospital;&lt;BR /&gt;array ya icd1-icd6;&lt;BR /&gt;if first.id then do; hosp=0; end;&lt;BR /&gt;do over ya;&lt;BR /&gt;if '311' le ya le '31199' then hosp=1;&lt;BR /&gt;end;&lt;BR /&gt;if last.id then output;&lt;BR /&gt;proc print; run;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 00:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567100#M159430</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-19T00:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567105#M159432</link>
      <description>&lt;P&gt;Post your code as a self-contained data step containing the datalines statement.&amp;nbsp; Very few people are going to download your attached SAS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post your code using the Insert SAS Code icon so it's formatted correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data seven; set one;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;by&lt;FONT color="#000000"&gt; hospital&lt;/FONT&gt; id ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;retain &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;hospital&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;array ya icd1-icd6;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if first.id then do; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;hosp&lt;/STRONG&gt;&lt;/FONT&gt;=0; end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;do over ya;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if '311' le ya le '31199' then &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;hosp&lt;/STRONG&gt;&lt;/FONT&gt;=1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if last.id then output;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;proc print; run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that your problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;the number of people within each hospital and overall&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd consider PROC FREQ or PROC SUMMARY and possibly PROC TRANSPOSE to get one row per ICD, then use a where clause with PROC FREQ/SUMMARY.&amp;nbsp; You could then merge back with your data if required, or re-transpose.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567105#M159432</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-06-19T01:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567109#M159435</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Please any correction in the logic of the statements can help.&lt;/P&gt;&lt;P&gt;I have 6 hospitals and i am trying to find the count in each hospital using the retain the statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567109#M159435</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-19T01:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567112#M159437</link>
      <description>Are you sure that this statement works?&lt;BR /&gt;&lt;BR /&gt;if '311' le ya le '31199' then hosp=1;&lt;BR /&gt;&lt;BR /&gt;That would be a character comparison so you could get weird results and I'd highly suggest an alternative method of coding this line. Unless you're 100% sure it works but I wouldn't be....</description>
      <pubDate>Wed, 19 Jun 2019 01:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567112#M159437</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-19T01:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567113#M159438</link>
      <description>&lt;P&gt;Fix the RETAIN statement to reference the variable you want to retain HOSP instead of the variable that is already in your dataset HOSPITAL.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567113#M159438</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-19T01:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567115#M159439</link>
      <description>&lt;P&gt;Thank you. I revised it. But i get stuck on the character vs numeric variable issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one; set two;&lt;BR /&gt;by hospital id visitdate;&lt;BR /&gt;retain depression;&lt;BR /&gt;array ya icd1-icd6;&lt;BR /&gt;if first.id then do depression=0; end;&lt;BR /&gt;do over ya;&lt;BR /&gt;if '311' le ya le '31199' then depression=1;&lt;BR /&gt;end;&lt;BR /&gt;if last.id then output;&lt;BR /&gt;proc print; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567115#M159439</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-19T01:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567116#M159440</link>
      <description>&lt;P&gt;You are right. It didn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way i can recode that? I just want ICD codes that fall between 311 and 31199. The ICD codes were coded as a character variable in our dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567116#M159440</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-19T01:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567118#M159441</link>
      <description>&lt;P&gt;What character vs numeric issue?&lt;/P&gt;
&lt;P&gt;You should NOT be storing ICD codes in numeric variables. First of all they are CODEs and not numbers. Also there are code where the leading zeros are important.&amp;nbsp; But even worse there are many ICD9 codes that have letters in them.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567118#M159441</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-19T01:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567119#M159442</link>
      <description>&lt;P&gt;You are right. They are stored as character variables. How do i find out which codes lie between '311' and '31199' in each hospital. I guess i would need to convert the character codes to numeric right? Because i tried running the code in character form and it didn't give me what i was looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567119#M159442</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-06-19T01:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567120#M159443</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;How do i find out which codes lie between '311' and '31199' in each hospital&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Define "between".&amp;nbsp; Is the list long?&amp;nbsp; Can you just use an IN() list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And post self-contained sample code so we can help you better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 01:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567120#M159443</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-06-19T01:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567121#M159444</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/236266"&gt;@ChuksManuel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You are right. They are stored as character variables. How do i find out which codes lie between '311' and '31199' in each hospital. I guess i would need to convert the character codes to numeric right? Because i tried running the code in character form and it didn't give me what i was looking for.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Codes between '311' and '31199' will work with clean data.&amp;nbsp; Although I don't think there are any valid codes in that range other than '311'.&amp;nbsp; Also make sure you haven't mistakenly stored codes that start with zero without the leading zero.&amp;nbsp; Otherwise you might include codes that should have started with '031'&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;031 Diseases due to other mycobacteria&lt;/PRE&gt;
&lt;P&gt;Show the data that is causing the trouble. Make a small self contained example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step is just reducing the data to one observation per hospital and id combination. If you want the total per hospital you will still need to count/add them.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 02:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567121#M159444</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-19T02:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567122#M159445</link>
      <description>&lt;P&gt;You could use an informat.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	invalue $icdCode "311" - "31199" = "Depression"
				other = "Other";
run;
data have;
	*Using informat to transform the data in this case, but you could use put(icd1,$icdCode.);
	input icd :$icdCode.;
datalines;
31125
32000
25000
311
31199
;;;
run;
data want;
	set have;
	if icd = "Depression" then hosp =1;	
	else hosp = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With a format, instead of an informat.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value $icdCode "311" - "31199" = "Depression"
				other = "Other";
run;
data have;
	length icd $12;
	input icd $;
datalines;
31125
32000
25000
311
31199
;;;
run;
data want;
	set have;
	icd_formated = put(icd,$icdCode.);
	if icd_formated = "Depression" then hosp =1;	
	else hosp = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 02:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain/m-p/567122#M159445</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-19T02:14:34Z</dc:date>
    </item>
  </channel>
</rss>

