<?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: Trying to group age's in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772535#M31091</link>
    <description>Please show the log from your code and the full code. &lt;BR /&gt;</description>
    <pubDate>Wed, 06 Oct 2021 19:04:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-10-06T19:04:29Z</dc:date>
    <item>
      <title>Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772521#M31089</link>
      <description>&lt;P&gt;Hello there, I am trying to run code on a set of individuals 18-90. I want to group them 18-30, 30-65 and 65+.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When running the code no changes take place. I am wondering if I could get some help with why my code is not working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if AGE &amp;lt; 30 then AGE_CAT30 = "18-30";&lt;BR /&gt;else if AGE = &amp;gt;30 then AGE_CAT30 = "30-65";&lt;/P&gt;&lt;P&gt;IF AGE &amp;gt; 65 THEN AGE_CAT65= "65+";&lt;BR /&gt;ELSE IF AGE = &amp;lt; 65+ THEN AGE_CAT65 = "UNDER65+";&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 18:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772521#M31089</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T18:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772535#M31091</link>
      <description>Please show the log from your code and the full code. &lt;BR /&gt;</description>
      <pubDate>Wed, 06 Oct 2021 19:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772535#M31091</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-06T19:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772554#M31094</link>
      <description>&lt;P&gt;Do you define a length for the Age_cat65 before use? If not the code you use will assign a length of 3 characters because the first time you use the variable you assign "65+" and that is only 3 characters. So "Under65+" will only show 3 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Strongly suggest that you consider learning to use formats. Then you likely only need one variable Age, and can create groups that are used by reporting, analysis and graphing procedures. A short example using a data set you should have available:&lt;/P&gt;
&lt;PRE&gt;Proc format;
value age13_
low - 13='13 and under'
14 - high='14 and older'
;
value age3grps
11,12,13 = '11,12 and 13'
14,15 = '14 and 15'
16,17 = '16 and 17'
;

title "Age13_ format";
proc print data=sashelp.class;
  var name age;
  format age age13_.;
run;
proc freq data=sashelp.class;
   format age age13_.;
   tables sex*age;
run;
title "Age3grps format";
proc print data=sashelp.class;
  var name age;
  format age age3grps.;
run;
proc freq data=sashelp.class;
   format age age3grps.;
   tables sex*age;
run;
title;
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Important:&lt;/STRONG&gt; Format names cannot end in a numeric value as the number would be interpreted as the number of characters to display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have had projects where we reported on up to 8 "standard" age groups. Then often we would get a question about "what happens if we change the age boundary from 25 to 26" (or 27, or multiple differences). Instead of creating a bunch of hard to keep track of variables we just make a new format and use that for the analysis or report.&lt;/P&gt;
&lt;P&gt;SAS also has a format type called Multilabel that would make overlapping groups as separate categories for a small number of procedures that honor them.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 19:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772554#M31094</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-06T19:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772740#M31101</link>
      <description>&lt;P&gt;&lt;BR /&gt;if AGE &amp;lt; 30 then AGE_CAT30 = "18-30";&lt;BR /&gt;else if AGE = &amp;gt;30 then AGE_CAT30 = "30-65";&lt;/P&gt;&lt;P&gt;IF AGE &amp;gt; 65 THEN AGE_CAT65= "65+";&lt;BR /&gt;ELSE IF AGE = &amp;lt; 65+ THEN AGE_CAT65 = "UNDER65+";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC FREQ data=WORK.vaccine_hesitancy_data;&lt;BR /&gt;TABLES (AGE) * VACCINEHESITANT/ MISSING CHISQ;&lt;/P&gt;&lt;P&gt;PROC TTEST data=WORK.vaccine_hesitancy_data;&lt;BR /&gt;VAR AGE;&lt;BR /&gt;CLASS VACCINEHESITANT;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772740#M31101</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T14:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772748#M31102</link>
      <description>&lt;P&gt;This isn't the full code, your IF statements must be in a DATA step, please show us the full DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please show us the log for this code. (All of it, every single line, with nothing deleted)&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772748#M31102</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-07T14:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772800#M31111</link>
      <description>&lt;P&gt;Attached is my full log and full code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for all the help&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 15:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772800#M31111</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T15:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772805#M31112</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ELSE IF AGE = &amp;lt; 65+ THEN AGE_CAT65 = "UNDER65+";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is invalid syntax in SAS. The + sign is invalid in &lt;FONT face="courier new,courier"&gt;age&amp;lt;=65+&lt;/FONT&gt;. Remove it and your code should work.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 16:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772805#M31112</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-07T16:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772815#M31113</link>
      <description>&lt;P&gt;Reposting my initial solution - from your previous question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your issue here shows some of the issues I noted in the previous thread. You really shouldn't code in that fashion, it makes your work hard to debug and fix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the updated code with that section corrected - note that I cannot test the code as I don't have your data so there's still the possibility of errors in here.&lt;STRONG&gt; I would highly suggest at minimum you add the GUESSINGROWS=MAX to your proc import and having the same data set name in the DATA and SET statement is very bad programming style and will cause you many issues over time.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.vaccine_hesitancy_data;
set work.vaccine_hesitancy_data;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fixed code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*****************
Import data
******************/
FILENAME REFFILE '/home/u57317860/Capstone data/vaccine_hesitancy_data.csv';


PROC IMPORT DATAFILE=REFFILE
DBMS=CSV
OUT=WORK.vaccine_hesitancy_data;
GETNAMES=YES;
GUESSINGROWS=MAX;
RUN;

PROC CONTENTS DATA=WORK.vaccine_hesitancy_data;
 RUN;


DATA vax_data;

SET vaccine_hesitancy_data;

IF VACCINEUPTAKE= 0 AND VACCINEINTEND IN (2,3,4,5,9) THEN VACCINEHESITANT=1;
ELSE VACCINEHESITANT= 0;

*check if the value is UNKNOWN;
IF SEX IN ("Unknow", "") THEN DELETE;

if AGE &amp;lt; 30 then AGE_CAT30 = "18-30";
else if AGE &amp;gt;=30 then AGE_CAT30 = "30-65";

IF AGE &amp;gt; 65 THEN AGE_CAT65= "65+";
ELSE IF AGE &amp;lt;= 65 THEN AGE_CAT65 = "UNDER65+";



RUN;


PROC FREQ data=vax_data;
TABLES (VACCINEUPTAKE VACCINEINTEND SEX) * VACCINEHESITANT/ MISSING CHISQ;
RUN;

PROC TTEST data=vax_data;
VAR AGE;
CLASS VACCINEHESITANT;
RUN;


PROC FREQ data=vax_data;
TABLES (SEX AGE POP EDUCATION IMPACTPHYSICAL IMPACTMENTAL IMPACTFAMILY IMPACTEMPLOYMENT) * VACCINEHESITANT/ MISSING CHISQ;
RUN;

*********ATTEMPTING TO RUN EDUCATION VARIABLE*******************;
PROC FREQ data=WORK.vax_data;
TABLES (EDUCATION) * VACCINEHESITANT/ MISSING CHISQ;
RUN;




PROC FREQ data=WORK.vax_data;
TABLES (AGE) * VACCINEHESITANT/ MISSING CHISQ;

PROC TTEST data=WORK.vax_data;
VAR AGE;
CLASS VACCINEHESITANT;
RUN;

PROC FORMAT;
VALUE POP_FMT
1= 'NHW'
2,3,4,5,6,7 = 'Other';
RUN;


PROC FREQ data=vax_data;

TABLES (POP) * VACCINEHESITANT/ MISSING CHISQ;

format POP POP_FMT.;

RUN;


PROC FREQ data=WORK.vax_data;
where not missing(livetestpos);
TABLES (livetestpos) * VACCINEHESITANT/ MISSING CHISQ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772815#M31113</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-07T17:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772843#M31117</link>
      <description>I ran the code exactly as you have it above and my FREQ Procedure table for age still list every individual row for ages 18-90 instead of grouping them into&lt;BR /&gt;18-30&lt;BR /&gt;30-65&lt;BR /&gt;65 and over&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Oct 2021 18:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772843#M31117</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T18:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772846#M31118</link>
      <description>I removed the + and all of my ages are still being shown as an individual row for ages 18 all the way through 90. I am still unable to categorize them 18-30, 30-65, and 65 and over&lt;BR /&gt;&lt;BR /&gt;Thank you,</description>
      <pubDate>Thu, 07 Oct 2021 18:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772846#M31118</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T18:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772847#M31119</link>
      <description>My age range is from 18-90&lt;BR /&gt;would I theoretically in the step below list all of my ages for example 18,19,20....all the way up to 90 for this to work?:&lt;BR /&gt;value age3grps&lt;BR /&gt;11,12,13 = '11,12 and 13'&lt;BR /&gt;14,15 = '14 and 15'&lt;BR /&gt;16,17 = '16 and 17'&lt;BR /&gt;;</description>
      <pubDate>Thu, 07 Oct 2021 18:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772847#M31119</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T18:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772861#M31120</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/401680"&gt;@Guerraje&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I removed the + and all of my ages are still being shown as an individual row for ages 18 all the way through 90. I am still unable to categorize them 18-30, 30-65, and 65 and over&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, the code I fixed leaves everything as individual rows. What type of categorization do you need? Show us the desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772861#M31120</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-07T19:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772875#M31121</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Did you run the PROC FREQ on the new variables, not AGE?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;So your new variables are AGE_CAT30 and AGE_CAT65.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code shown only references the original variable AGE, not the newly recoded values so you'll see only the original values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=vax_data;
table age*age_cat30;
table age*age_cat65;
table age_cat30;
table age_cat65;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/401680"&gt;@Guerraje&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I ran the code exactly as you have it above and my FREQ Procedure table for age still list every individual row for ages 18-90 instead of grouping them into&lt;BR /&gt;18-30&lt;BR /&gt;30-65&lt;BR /&gt;65 and over&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&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, 07 Oct 2021 20:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772875#M31121</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-07T20:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772908#M31131</link>
      <description>&lt;P&gt;I used word to make a mock table of what I am trying to do.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My project is looking at vaccine hesitancy. Vaccine hesitancy is coded as 1, and nonhesitant is coded as 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;so my columns are labeled as:&lt;/P&gt;&lt;P&gt;AGE&amp;nbsp; &amp;nbsp;HESTIANT (1)&amp;nbsp; &amp;nbsp;NONHESITANT (0)&lt;/P&gt;&lt;P&gt;18-30&lt;/P&gt;&lt;P&gt;30-65&lt;/P&gt;&lt;P&gt;65+&lt;/P&gt;&lt;P&gt;Then my age as the rows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to make all the numeric age rows into categorical rows instead.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 23:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/772908#M31131</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-07T23:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/773000#M31139</link>
      <description>&lt;P&gt;Okay, how about this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value agef 0-29='0-29' 30-65='30-65' 65-high='&amp;gt;65';
run;

proc freq data = have;
    tables &lt;STRONG&gt;age*vaccinehesitant;
&lt;/STRONG&gt;    format age agef.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your method won't work because you have split the ages into TWO DIFFERENT age variables each with two levels, one named AGE_CAT30 and AGE_CAT65, when you really just need the age variable split three ways, not split into two variables with two levels.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 15:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/773000#M31139</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-08T15:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to group age's</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/773207#M31146</link>
      <description>&lt;P&gt;SUCCESS!!&lt;/P&gt;&lt;P&gt;Thank you so much for sticking through&amp;nbsp; this with me. I am only a month into SAS, and still learning so much.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 10:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-group-age-s/m-p/773207#M31146</guid>
      <dc:creator>Guerraje</dc:creator>
      <dc:date>2021-10-09T10:30:12Z</dc:date>
    </item>
  </channel>
</rss>

