<?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: Flag variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857922#M37857</link>
    <description>You quite understood my query correctly. Many thanks.</description>
    <pubDate>Thu, 09 Feb 2023 03:12:11 GMT</pubDate>
    <dc:creator>Pivot_e</dc:creator>
    <dc:date>2023-02-09T03:12:11Z</dc:date>
    <item>
      <title>Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857844#M37849</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Kindly help with the appropriate SAS code.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Please I want to Create 3 new disease group summary flag variables Dx_G1 to Dx_G3for each patient where:&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Dx_G1 = 1 if patient has any disease code value from 000-100 inclusive, otherwise 0,&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Dx_G2 = 1 if patient has any disease code value from 101-200 inclusive, otherwise 0,&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Dx_GP3= 1 if patient has any disease code value from 201-300 inclusive, otherwise 0.&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Note we have :&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Disease code1&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Disease code2&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Disease code 3&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857844#M37849</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-08T20:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857889#M37850</link>
      <description>&lt;P&gt;Are your disease codes numeric or character? This is extremely important as character values and "inclusive" for 000-100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It helps to provide a clearer example of your actual variable names and types. If you are not familiar with that run Proc Contents on your data set and share that information.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 21:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857889#M37850</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-08T21:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857892#M37851</link>
      <description>Yes the disease codes are numeric.&lt;BR /&gt;Please also note: for instance the Dx_G1 should check three variables (disease_code1, disease_code2, diseases_code3) if there are codes 000 to 100 and then generate Dx_G1 as 1</description>
      <pubDate>Wed, 08 Feb 2023 21:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857892#M37851</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-08T21:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857898#M37852</link>
      <description>&lt;P&gt;You try this one. If I understood your query correctly, you want to create flag by looking at variables disease code 1 ,2,3 for mentioned range of disease codes then below code might work for you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just pass the input data set name and you'll have a new data set with flag variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;&lt;BR /&gt;create table new_dataset as select *,&lt;BR /&gt;	CASE WHEN (disease_code1 between 000 and 100) OR&lt;BR /&gt;	          (disease_code2 between 000 and 100) OR&lt;BR /&gt;	          (disease_code3 between 000 and 100) THEN 1&lt;BR /&gt;			ELSE 0 END as Dx_G1 ,&lt;BR /&gt;	CASE WHEN (disease_code1 between 101 and 200) OR &lt;BR /&gt;	          (disease_code2 between 101 and 200) OR &lt;BR /&gt;	          (disease_code3 between 101 and 200) THEN 1&lt;BR /&gt;			ELSE 0 END as Dx_G2 ,			&lt;BR /&gt;	CASE WHEN (disease_code1 between 201 and 300) OR&lt;BR /&gt;			  (disease_code1 between 201 and 300) OR&lt;BR /&gt;			  (disease_code1 between 201 and 300) THEN 1&lt;BR /&gt;			ELSE 0 END as Dx_G3 &lt;BR /&gt;		&lt;BR /&gt;from input_dataset;&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 21:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857898#M37852</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-02-08T21:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857922#M37857</link>
      <description>You quite understood my query correctly. Many thanks.</description>
      <pubDate>Thu, 09 Feb 2023 03:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857922#M37857</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T03:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857924#M37858</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430243"&gt;@MayurJadhav&lt;/a&gt;. Thank you for the response, it was helpful. Please can you educate me on the use of "," i.e comma to end the statements as against the ";" semicolon commonly used</description>
      <pubDate>Thu, 09 Feb 2023 03:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857924#M37858</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T03:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857925#M37859</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439321"&gt;@Pivot_e&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430243"&gt;@MayurJadhav&lt;/a&gt;. Thank you for the response, it was helpful. Please can you educate me on the use of "," i.e comma to end the statements as against the ";" semicolon commonly used&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Commas do not end statements.&amp;nbsp; But commas are used in many places. And SQL in particular is EXTREMELY fond of using commas.&amp;nbsp; In the example code the commas are used to separate the individual variables that are being "selected" by the SELECT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formatting hint:&amp;nbsp; I find it is MUCH EASIER for humans to see (especially when scanning) such "continuation" characters if you place that at the start of the line that the code is continuing onto instead of the end of the previous line.&amp;nbsp; That way they can be aligned and scanned without having to move you eyes' focus back and forth across the page.&lt;/P&gt;
&lt;P&gt;Also when you have single statement (like many SQL SELECT statements) that spans multiple lines it helps to locate the semicolon that ends the statement on a new line.&amp;nbsp; Just like you would locate and END to closes a DO block on a new line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table new_dataset as 
  select *
	,CASE WHEN (disease_code1 between 000 and 100) OR
	          (disease_code2 between 000 and 100) OR
	          (disease_code3 between 000 and 100) THEN 1
			ELSE 0 
     END as Dx_G1
	,CASE WHEN (disease_code1 between 101 and 200) OR 
	          (disease_code2 between 101 and 200) OR 
	          (disease_code3 between 101 and 200) THEN 1
			ELSE 0 
     END as Dx_G2			
	,CASE WHEN (disease_code1 between 201 and 300) OR
			  (disease_code1 between 201 and 300) OR
			  (disease_code1 between 201 and 300) THEN 1
			ELSE 0 
      END as Dx_G3 
from input_dataset
;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 04:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857925#M37859</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-09T04:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857965#M37866</link>
      <description>This is quite helpful.&lt;BR /&gt;I really appreciate your timely response.&lt;BR /&gt;Please I will like to follow you (to be mentored further). I would appreciate it if you can share your handle or WhatsApp contact.&lt;BR /&gt;Regards,</description>
      <pubDate>Thu, 09 Feb 2023 08:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857965#M37866</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T08:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857966#M37867</link>
      <description>Please I will like to follow you (to be mentored further). I would appreciate it if you can share your handle or WhatsApp contact.&lt;BR /&gt;Regards,</description>
      <pubDate>Thu, 09 Feb 2023 08:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857966#M37867</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T08:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857967#M37868</link>
      <description>Please I have another question.&lt;BR /&gt;I like to generate and report the distribution of a variable waiting time. Please How can I do this on SAS?</description>
      <pubDate>Thu, 09 Feb 2023 09:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857967#M37868</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T09:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857970#M37869</link>
      <description>&lt;P&gt;Data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set input_dataset;
   Dx_g1 = ( (0 le disease_code1 le 100) or 
             (0 le disease_code2 le 100) or 
             (0 le disease_code3 le 100) 
           );
   Dx_g2 = ( (101 le disease_code1 le 200) or 
             (101 le disease_code2 le 200) or 
             (101 le disease_code3 le 200) 
            );
   Dx_g3 = ( (201 le disease_code1 le 300) or 
             (201 le disease_code2 le 300) or 
             (201 le disease_code3 le 300) 
           );
run;&lt;/PRE&gt;
&lt;P&gt;You may ask how 1/0 get assigned with the above code. SAS treats the results of logical comparisons as numeric 1/0 for true or false. So the result of the OR comparisons will result in true or false or 1/0 results.&lt;/P&gt;
&lt;P&gt;The SQL could also have been written&lt;/P&gt;
&lt;PRE&gt;,( (201 le disease_code1 le 300) or 
   (201 le disease_code2 le 300) or 
   (201 le disease_code3 le 300) 
  ) as Dx_g3&lt;/PRE&gt;
&lt;P&gt;instead of using a case/when construct. This comparison typically executes faster than a CASE/WHEN or data step IF/THEN/ELSE block of code. You may not notice the time difference with only a few thousand records but when you get to billions the time can add up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why use a data step instead of SQL? Depending on the exact code involved SQL may result in reordering the data set and if you have any operation that requires specific order of the data then you are not guaranteed to get the same results as SQL does not process sets sequentially. Also unless one of the SQL specific features such as joins between multiple sets are involved the Data step often executes quicker.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This forum prefers that you start a new thread when asking different questions not closely related to this current one.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 09:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857970#M37869</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-09T09:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857997#M37879</link>
      <description>Wow!... I am really learning here.&lt;BR /&gt;Many thanks.</description>
      <pubDate>Thu, 09 Feb 2023 11:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/857997#M37879</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T11:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/858026#M37884</link>
      <description>&lt;P&gt;Please I have another question. I like to generate and report the distribution of a variable waiting time.&lt;/P&gt;&lt;P&gt;Please How can I do this on SAS?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 14:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/858026#M37884</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T14:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/858133#M37896</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430243"&gt;@MayurJadhav&lt;/a&gt; please what will the codes be for disease_code1 to disease code_3 [character (3) format ‘nnn’]</description>
      <pubDate>Thu, 09 Feb 2023 21:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-variables/m-p/858133#M37896</guid>
      <dc:creator>Pivot_e</dc:creator>
      <dc:date>2023-02-09T21:12:16Z</dc:date>
    </item>
  </channel>
</rss>

