<?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: SAS Query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803153#M316249</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420355"&gt;@Mjooda&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;One approach is to use proc format and proc means.&lt;BR /&gt;I have explained by means of an example,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc format;
value agegroup
       0  -&amp;lt; 5   = "Infant"
        5-&amp;lt;15   = "1"
       15-&amp;lt;25   = "2"
       25 -&amp;lt;35   = "3"
       35-&amp;lt;45   = "4"
       45-&amp;lt;55   = "5"
       55-&amp;lt;65   = "6"
       65-&amp;lt;75   = "7"
       75-&amp;lt;85   = "8"
       85- HIGH  = "Senior";
data class2;
Format age agegroup.;
set sashelp.class;
run;
       
proc means data=class2 sum  nonobs ;
Class Age ;
output out=sumout(Rename=(_FREQ_=NUM_STUDENTS AGE=AGE_GRP) WHERE=(_TYPE_=1) ) sum(weight) =GP_WT;;
run;
data sumout (drop=_TYPE_);
set sumout ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The final output will be as follows&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1647881391597.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69627iBD59A1B43D91EDEF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1647881391597.png" alt="Sajid01_0-1647881391597.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2022 16:50:18 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2022-03-21T16:50:18Z</dc:date>
    <item>
      <title>SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803092#M316223</link>
      <description>&lt;P&gt;Good morning!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I kindly need help in writing this query for a practice pull.&lt;/P&gt;&lt;P&gt;If I can get help from anyone ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;total death counts over the 5 year period 2015-2019 at the zipcode level&lt;/P&gt;&lt;P&gt;by age groups: under 5, 5-14, 15-24, 25-34, 35-44, 45-54, 55-64, 65-74, 75-84, and 85 and above.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table Brooking as
select count (CRESIDZIP_EXT)
from CLEANED.death2020
where age&amp;lt;=5 and age&amp;gt;=85;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have tried several queries but still not getting the info needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 15:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803092#M316223</guid>
      <dc:creator>Mjooda</dc:creator>
      <dc:date>2022-03-21T15:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803106#M316232</link>
      <description>&lt;P&gt;how about these two codes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Brooking as
  select count (CRESIDZIP_EXT),
    case 
      when(    age&amp;lt; 5) then 0
      when( 5&amp;lt;=age&amp;lt;14) then 1
      when(15&amp;lt;=age&amp;lt;24) then 2
      when(25&amp;lt;=age&amp;lt;34) then 3
      when(35&amp;lt;=age&amp;lt;44) then 4
      when(45&amp;lt;=age&amp;lt;54) then 5
      when(55&amp;lt;=age&amp;lt;64) then 6
      when(65&amp;lt;=age&amp;lt;74) then 7
      when(75&amp;lt;=age&amp;lt;84) then 8
      when(85&amp;lt;=age)    then 9
      else .
    end as age_group
  from CLEANED.death2020
  group by age_group;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Brooking as
  select count (CRESIDZIP_EXT),
         round(age/10,1) as age_group
  from CLEANED.death2020
  group by age_group;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 15:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803106#M316232</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-03-21T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803109#M316233</link>
      <description>&lt;P&gt;Okay thanks would try that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 15:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803109#M316233</guid>
      <dc:creator>Mjooda</dc:creator>
      <dc:date>2022-03-21T15:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803142#M316241</link>
      <description>&lt;P&gt;You might want to consider using PROC FORMAT and PROC FREQ to do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create some sample data */
data bulk ;
	set sashelp.class ;
	do i=1 to 5 ;
		output ;
	end ;
run ;

/* Creatge a custom format */
/* https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1xidhqypi0fnwn1if8opjpqpbmn.htm */
proc format ;
	value age 
		11-12   = "11-12" 
		13-14   = "13-14"
		15-high = "Over 14"
		;
run ;

proc sql ;
	/* counts unformatted */
	create table counts as
	select 
		age, count(*)
	from
		bulk 
	group by age ;

	;
	/* counts formatted */
	create table countsF as
	select 
		putn(age,"age.") as ageF , count(*)
	from
		bulk 
	group by ageF ;

	;

run ;

/* If you just want counts, then PROC FREQ might be a better option */
/* https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_freq_toc.htm */
proc freq data=bulk noprint ;
	format age age. ;
	table age / out=freqOut ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 16:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803142#M316241</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-03-21T16:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803153#M316249</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/420355"&gt;@Mjooda&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;One approach is to use proc format and proc means.&lt;BR /&gt;I have explained by means of an example,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc format;
value agegroup
       0  -&amp;lt; 5   = "Infant"
        5-&amp;lt;15   = "1"
       15-&amp;lt;25   = "2"
       25 -&amp;lt;35   = "3"
       35-&amp;lt;45   = "4"
       45-&amp;lt;55   = "5"
       55-&amp;lt;65   = "6"
       65-&amp;lt;75   = "7"
       75-&amp;lt;85   = "8"
       85- HIGH  = "Senior";
data class2;
Format age agegroup.;
set sashelp.class;
run;
       
proc means data=class2 sum  nonobs ;
Class Age ;
output out=sumout(Rename=(_FREQ_=NUM_STUDENTS AGE=AGE_GRP) WHERE=(_TYPE_=1) ) sum(weight) =GP_WT;;
run;
data sumout (drop=_TYPE_);
set sumout ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The final output will be as follows&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1647881391597.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69627iBD59A1B43D91EDEF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1647881391597.png" alt="Sajid01_0-1647881391597.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 16:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803153#M316249</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-03-21T16:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803156#M316250</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 16:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803156#M316250</guid>
      <dc:creator>Mjooda</dc:creator>
      <dc:date>2022-03-21T16:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803157#M316251</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 16:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803157#M316251</guid>
      <dc:creator>Mjooda</dc:creator>
      <dc:date>2022-03-21T16:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803193#M316264</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Welcome to the SAS forums!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is good that you are thanking others for their proposed solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are happy with what you have received, then a further show of gratitude is to mark one of the responses as a solution (not this post) as this increases their solution count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, this way other contributors can see that nothing further is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 18:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Query/m-p/803193#M316264</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2022-03-21T18:22:14Z</dc:date>
    </item>
  </channel>
</rss>

