<?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 Creating a flag SAS SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859626#M339606</link>
    <description>&lt;P&gt;I have a gender variable in the old dataset from a week ago and a gender variable in the current dataset. I have created old and new versions of these variables and combined them into a table called joined.&lt;/P&gt;&lt;P&gt;My goal is to create a flag that will show if there are differences between the old and the new gender variable +- 100. I'd like to know if there is drops.&lt;/P&gt;&lt;P&gt;The gender variable is categorical (categories are: female, male, unknown).&lt;/P&gt;&lt;P&gt;Is there a way for me to create flags using proc sql -I will need to do this for the other variables including sex, race, age, etc. What is the easiest way to create a flag and also show the counts of the variables? The end goal would be three columns the counts of the two gender variables and then a flag saying if there was an increase or decrease of 100 from the two weeks.&lt;/P&gt;&lt;P&gt;This is the code I have so far:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table joined as&lt;/P&gt;&lt;P&gt;select coalesce(a.person_key, b.person_key) as person_key,&lt;/P&gt;&lt;P&gt;a.gender_old, b.gender_new,&lt;/P&gt;&lt;P&gt;a.sexor_old, b.sexor_new,&lt;/P&gt;&lt;P&gt;a.race_cd_old, b.race_cd_new,&lt;/P&gt;&lt;P&gt;a.age_group_old, b.age_group_new,&lt;/P&gt;&lt;P&gt;a.sex_old, b.sex_new,&lt;/P&gt;&lt;P&gt;a.peh1_old, b.peh1_new,&lt;/P&gt;&lt;P&gt;a.peh2_old, b.peh2_new,&lt;/P&gt;&lt;P&gt;a.dose_total_old, b.dose_total_new&lt;/P&gt;&lt;P&gt;from oldperson a&lt;/P&gt;&lt;P&gt;full join newperson b&lt;/P&gt;&lt;P&gt;on a.person_key = b.person_key;&lt;/P&gt;&lt;P&gt;quit; /Goal: Flag significant increases and flag ANY drops./&lt;/P&gt;</description>
    <pubDate>Sun, 19 Feb 2023 15:59:35 GMT</pubDate>
    <dc:creator>xxartpopxx</dc:creator>
    <dc:date>2023-02-19T15:59:35Z</dc:date>
    <item>
      <title>Creating a flag SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859626#M339606</link>
      <description>&lt;P&gt;I have a gender variable in the old dataset from a week ago and a gender variable in the current dataset. I have created old and new versions of these variables and combined them into a table called joined.&lt;/P&gt;&lt;P&gt;My goal is to create a flag that will show if there are differences between the old and the new gender variable +- 100. I'd like to know if there is drops.&lt;/P&gt;&lt;P&gt;The gender variable is categorical (categories are: female, male, unknown).&lt;/P&gt;&lt;P&gt;Is there a way for me to create flags using proc sql -I will need to do this for the other variables including sex, race, age, etc. What is the easiest way to create a flag and also show the counts of the variables? The end goal would be three columns the counts of the two gender variables and then a flag saying if there was an increase or decrease of 100 from the two weeks.&lt;/P&gt;&lt;P&gt;This is the code I have so far:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table joined as&lt;/P&gt;&lt;P&gt;select coalesce(a.person_key, b.person_key) as person_key,&lt;/P&gt;&lt;P&gt;a.gender_old, b.gender_new,&lt;/P&gt;&lt;P&gt;a.sexor_old, b.sexor_new,&lt;/P&gt;&lt;P&gt;a.race_cd_old, b.race_cd_new,&lt;/P&gt;&lt;P&gt;a.age_group_old, b.age_group_new,&lt;/P&gt;&lt;P&gt;a.sex_old, b.sex_new,&lt;/P&gt;&lt;P&gt;a.peh1_old, b.peh1_new,&lt;/P&gt;&lt;P&gt;a.peh2_old, b.peh2_new,&lt;/P&gt;&lt;P&gt;a.dose_total_old, b.dose_total_new&lt;/P&gt;&lt;P&gt;from oldperson a&lt;/P&gt;&lt;P&gt;full join newperson b&lt;/P&gt;&lt;P&gt;on a.person_key = b.person_key;&lt;/P&gt;&lt;P&gt;quit; /Goal: Flag significant increases and flag ANY drops./&lt;/P&gt;</description>
      <pubDate>Sun, 19 Feb 2023 15:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859626#M339606</guid>
      <dc:creator>xxartpopxx</dc:creator>
      <dc:date>2023-02-19T15:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a flag SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859628#M339607</link>
      <description>&lt;P&gt;Do you want to compare individual observations and see if the value has changed?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table gender_check as
select coalesce(a.id,b.id) as id
     , case when (a.sex ne b.sex) then cats(a.sex,'-&amp;gt;',b.sex) 
            else ' '
       end as sex_flag
from old a
full join new b
on a.id =b.id
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or do you want to compare the distribution of values between the two datasets?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select coalesce(a.sex,b.sex) as sex
     , a.count as old_count
     , b.count as new_count
     , a.count - b.count as count_diff
from (select sex,count(*) as count from old group by sex) a
full join (select sex,count(*) as count from new group by sex) b
  on a.sex = b.sex
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Feb 2023 16:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859628#M339607</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-19T16:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a flag SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859629#M339608</link>
      <description>&lt;P&gt;I'd want to look at the distribution of values so the second code block may work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;How would I add a flag in the proc freq to say if the count_diff is more than 100?&lt;/P&gt;</description>
      <pubDate>Sun, 19 Feb 2023 16:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859629#M339608</guid>
      <dc:creator>xxartpopxx</dc:creator>
      <dc:date>2023-02-19T16:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a flag SAS SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859689#M339628</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360788"&gt;@xxartpopxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'd want to look at the distribution of values so the second code block may work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;How would I add a flag in the proc freq to say if the count_diff is more than 100?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is no PROC FREQ mentioned in this thread. Only PROC SQL. In PROC SQL, you perform a test to see if the difference is greater than 100 using the CASE WHEN statement in PROC SQL. If it is greater than 100, you assign the flag variable a value of 1, otherwise you assign the flag variable a value of zero.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 11:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-flag-SAS-SQL/m-p/859689#M339628</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-20T11:41:09Z</dc:date>
    </item>
  </channel>
</rss>

