<?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 proc freqs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-freqs/m-p/736880#M229664</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with birth certificate data and my raw data has the variable "MonthCareBegan" which is a character variable listed as a number 1-99 (missing data is either a blank, question mark or #99). I want to make three new variables: tri1, tri2, tri3 to determine which trimester the mother started prenatal care.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data project.project1;&lt;BR /&gt;set project.project1;&lt;BR /&gt;length tri1 $3.&lt;BR /&gt;tri2 $3.&lt;BR /&gt;tri3 $3.;&lt;BR /&gt;If MonthCareBegan=' ' or '99' or '?' then tri1=' ' and tri2=' ' and tri3=' ';&lt;BR /&gt;Else if MonthCareBegan = "1" OR "2" OR "3" then tri1="Yes";&lt;BR /&gt;else if MonthCareBegan = "4" OR "5" OR "6" then tri2="Yes";&lt;BR /&gt;else tri3="Yes";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is what i'm getting...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krisk_0-1619383417685.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58669i6FB1BFB93720809C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="krisk_0-1619383417685.png" alt="krisk_0-1619383417685.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 25 Apr 2021 20:48:07 GMT</pubDate>
    <dc:creator>krisk</dc:creator>
    <dc:date>2021-04-25T20:48:07Z</dc:date>
    <item>
      <title>proc freqs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freqs/m-p/736880#M229664</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with birth certificate data and my raw data has the variable "MonthCareBegan" which is a character variable listed as a number 1-99 (missing data is either a blank, question mark or #99). I want to make three new variables: tri1, tri2, tri3 to determine which trimester the mother started prenatal care.&amp;nbsp;&lt;/P&gt;&lt;P&gt;data project.project1;&lt;BR /&gt;set project.project1;&lt;BR /&gt;length tri1 $3.&lt;BR /&gt;tri2 $3.&lt;BR /&gt;tri3 $3.;&lt;BR /&gt;If MonthCareBegan=' ' or '99' or '?' then tri1=' ' and tri2=' ' and tri3=' ';&lt;BR /&gt;Else if MonthCareBegan = "1" OR "2" OR "3" then tri1="Yes";&lt;BR /&gt;else if MonthCareBegan = "4" OR "5" OR "6" then tri2="Yes";&lt;BR /&gt;else tri3="Yes";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is what i'm getting...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krisk_0-1619383417685.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58669i6FB1BFB93720809C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="krisk_0-1619383417685.png" alt="krisk_0-1619383417685.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Apr 2021 20:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freqs/m-p/736880#M229664</guid>
      <dc:creator>krisk</dc:creator>
      <dc:date>2021-04-25T20:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc freqs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freqs/m-p/736882#M229666</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376835"&gt;@krisk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working with birth certificate data and my raw data has the variable "MonthCareBegan" which is a character variable listed as a number 1-99 (missing data is either a blank, question mark or #99). I want to make three new variables: tri1, tri2, tri3 to determine which trimester the mother started prenatal care.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data project.project1;&lt;BR /&gt;set project.project1;&lt;BR /&gt;length tri1 $3.&lt;BR /&gt;tri2 $3.&lt;BR /&gt;tri3 $3.;&lt;BR /&gt;If MonthCareBegan=' ' or '99' or '?' then tri1=' ' and tri2=' ' and tri3=' ';&lt;BR /&gt;Else if MonthCareBegan = "1" OR "2" OR "3" then tri1="Yes";&lt;BR /&gt;else if MonthCareBegan = "4" OR "5" OR "6" then tri2="Yes";&lt;BR /&gt;else tri3="Yes";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this is what i'm getting...&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="krisk_0-1619383417685.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58669i6FB1BFB93720809C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="krisk_0-1619383417685.png" alt="krisk_0-1619383417685.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you read the log for the data step?&lt;/P&gt;
&lt;P&gt;If you want to assign values to multiple variables after an "IF" then you use a do block:&lt;/P&gt;
&lt;PRE&gt;If MonthCareBegan=' ' or MonthCareBegan= '99' or MonthCareBegan= '?' then do;
   tri1=' ' ;
   tri2=' ' ;
   tri3=' ';
end;&lt;/PRE&gt;
&lt;P&gt;Second if you want to compare a single variable to a list of values you either repeat the variable name with each comparison:&lt;/P&gt;
&lt;PRE&gt;Else if MonthCareBegan = "1" OR MonthCareBegan = "2" OR MonthCareBegan = "3" then tri1="Yes";&lt;/PRE&gt;
&lt;P&gt;Or specifically for checking multiple values as equal us the IN operator:&lt;/P&gt;
&lt;PRE&gt; if MonthCareBegan IN ( "1" "2" "3") then tri1="Yes";&lt;/PRE&gt;
&lt;P&gt;(both your variables)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a final hint: You are likely much better off creating a single variable that holds the trimester of start&lt;/P&gt;
&lt;PRE&gt;if MonthCareBegan IN ( "1" "2" "3") then tri = 1;
else if MonthCareBegan IN ( "4" "5" "6") then tri=2;
else if MonthCareBegan IN ( "7" "8" "9") then tri=3;

label tri='Trimester prenatal care starts';&lt;/PRE&gt;
&lt;P&gt;Then when some asks a question like "are there differences in when prenatal care starts between (values of some other demographic category like race, age, ethnicity, geographic location) you use something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables tri * (other variable).&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;Otherwise with 3 variables you get to manually do lots of extra work to get meaningful percentages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For almost any purpose involving categories it is more flexible to have a single variable holding the categories instead of creating multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you will find that creating custom formats may even be easier.&lt;/P&gt;
&lt;PRE&gt;data have;
   input MonthCareBegan $;
datalines;
' '
.
99
1
2
3
4
5
6
7
8
9
;

proc format;
value $tri
"1","2","3"= "1"
"4","5","6"= "2"
"7","8","9"= "3"
other= .
;
;
proc freq data=have;
   tables monthcarebegan /;
   format monthcarebegan $tri.;
run;&lt;/PRE&gt;
&lt;P&gt;Groups created by custom formats will be honored by all the SAS reporting and analysis procedures and most graphing procedures.&lt;/P&gt;
&lt;P&gt;Advantage of formats is you do not have to change data. I could change the FORMAT definition values to read "1st Trimester" and similar and not change the data and the summary would read nicely.&lt;/P&gt;
&lt;P&gt;Plus if someone wants to know about 1st trimester vs 2d and 3rd combined, a different custom format would work without changing the data.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 14:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freqs/m-p/736882#M229666</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-26T14:39:22Z</dc:date>
    </item>
  </channel>
</rss>

