<?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 macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479224#M286469</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*CREATING A MACRO TO STORE THE TOTAL NUMBER OF PATEINTS AS A DYNAMIC DENOMINATOR  */

%macro denom ;
	
	proc sql ;
		select N(enrolid) into:denom
		from derived._01_esrd;
	quit ;
		
	%put the denominator is  &amp;amp;denom. yay this macro worked;
	
		
proc means data=derived._01_esrd mean median  Q1 Q3;
	var age  enrol_dur;
	output out=stat_age mean()= median()= STD()= Q1()= Q3()= Min()= Max()=/autoname; 
run;

/*DEMO TABLE WITHOUT MACROS*/
proc sql ;
	create table _02_demo as 
	select 1 as seq, "Total Cohort" as col, 	N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where enrolid 		union 
	select 2 as seq, "Gender" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where not enrolid 	union 
	select 3 as seq, "Female" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where sex='2' 		union 
	select 4 as seq, "Male" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where sex='1' 		union 
	select 5 as seq, "Type of Dialysis" as col, 	N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where not enrolid 	union 
	select 6 as seq, "age" as col, 			age_mean as N, age_median as percent 			from stat_age 			 		union 
	select 7 as seq, "Enrollment Duration" as col, 	enrol_dur_mean as N, enrol_dur_median as percent	from stat_age 			  
;
quit ;

%mend denom; 
%denom ;

ods csv file  = "/data1/projects/yellow/YVM0002aq/output/demo.csv" ;

	proc print data =_02_demo ;
	run ;
	
ods csv close ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what my actual code looks like after alterations. I want a MACROS for the numbers as seq and for the where condition as parameters&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 19:21:01 GMT</pubDate>
    <dc:creator>manya92</dc:creator>
    <dc:date>2018-07-18T19:21:01Z</dc:date>
    <item>
      <title>sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479162#M286464</link>
      <description>&lt;P&gt;How can I develop MACROS that helps me make a Demographic table that looks like this ?&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ESRD Group&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Characteristic&lt;/TD&gt;&lt;TD&gt;No. of patients&lt;/TD&gt;&lt;TD&gt;No. of patients&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Total cohort&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Gender&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Female&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Male&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Peritoneal&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hemodialysis&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;Mean&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Median (IQR)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Age&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Enrollment Duration&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code that i wrote is this :-&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*CREATING A MACRO TO STORE THE TOTAL NUMBER OF PATEINTS AS A DYNAMIC DENOMINATOR  */

%macro denom (whrcls=, label=, type= ) ;
	
	proc sql ;
		select N(enrolid) into: denom
		from derived._01_esrd;
	quit ;
	
	data _02_demographics ;
		set derived._01_esrd ;
		where &amp;amp;whrcls. ;
	run ;
	
		
	%put the denominator is  &amp;amp;denom. yay this macro worked;
	
		
proc means data=_02_stat mean median  Q1 Q3;
	var age  enrol_dur;
	output out=stat_age mean()= median()= STD()= Q1()= Q3()= Min()= Max()=/autoname; 
run;

/*CREATING THE DEMOGRAPHICS TABLE */

proc sql ;
	create table _02_demo_&amp;amp;type.
	select 1 as col, &amp;amp;label. as cat, N(enrolid) as N, N(enrolid)/&amp;amp;denom.  as Percent from _02_demographics union ;
quit ;

%mend denom(whrcls=,label=) ;
%denom(PatiendID, "Total Cohort" ) ;
%denom(not PatientID, "Gender") ;
%denom(sex = 2, "Female") ;
%denom(sex =1, "Male") ;
%denom(not PatientID, "Type of Dialysis");
%denom(code in ('90935','90937','90999','99512','90945','90947'), "Dialysis") ;
%denom(PatientID,"Age") ;
%denom(PatientID,"Enrollment Duration");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to create a MACROS for the serial number of rows : - eg where i have written select 1 as col, I want a MACROS which can go to the next number , 2 as col etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 17:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479162#M286464</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-18T17:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479167#M286465</link>
      <description>&lt;P&gt;The usual advice, which I think applies here, is for you to get the code running without macros, for just one condition. Once you do that, turning it into a macro should be relatively easy. Can you show us such code, without macros, that works for just one condition?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 17:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479167#M286465</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-18T17:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479174#M286466</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*CREATING A MACRO TO STORE THE TOTAL NUMBER OF PATEINTS AS A DYNAMIC DENOMINATOR  */

%macro denom (whrcls=, label=, type= ) ;
	
	proc sql ;
		create table _02_dt 
		select N(enrolid) into: denom
		from derived._01_esrd;
	quit ;
		
	%put the denominator is  &amp;amp;denom. yay this macro worked;
	
		
proc means data=_02_stat mean median  Q1 Q3;
	var age  enrol_dur;
	output out=stat_age mean()= median()= STD()= Q1()= Q3()= Min()= Max()=/autoname; 
run;

/*DEMO TABLE WITHOUT MACROS*/
proc sql ;
	create table _02_demo 
	select 1 as seq, "Total Cohort" as col, 	N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent, from _02_dt where enrolid 	union 
	select 2 as seq, "Gender" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent, from _02_dt where not enrolid 	union 
	select 3 as seq, "Female" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent, from _02_dt where sex=2 	union 
	select 4 as seq, "Male" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent, from _02_dt where sex=1 	union 
	select 5 as seq, "Type of Dialysis" as col, 	N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent, from _02_dt where not enrolid 	union 
	select 6 as seq, "Dialysis" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent, from _02_dt where code in ('90935','90937','90999','99512','90945','90947') 	union 
	select 7 as seq, "Age" as col, 			mean_age as N, median_age as percent  		from _02_stat where PatientID 	union 
	select 8 as seq, "Enrollment Duration" as col, 	mean_age as N, median_age as percent 		from _02_stat where PatientID ; 
quit ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is my code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 17:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479174#M286466</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-18T17:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479193#M286467</link>
      <description>&lt;P&gt;Did you read my previous message ?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 18:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479193#M286467</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-18T18:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479214#M286468</link>
      <description>&lt;P&gt;Does this code, without macros actually work, or does it have errors?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the data set created by PROC SQL, named _02_dt,&amp;nbsp;related to the data set used in PROC MEANS, which is named _02_stat?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your PROC SQL still uses the macro variable &amp;amp;denom, I think it would be helpful to have working code without macros and without macro variables.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 19:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479214#M286468</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-18T19:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479224#M286469</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*CREATING A MACRO TO STORE THE TOTAL NUMBER OF PATEINTS AS A DYNAMIC DENOMINATOR  */

%macro denom ;
	
	proc sql ;
		select N(enrolid) into:denom
		from derived._01_esrd;
	quit ;
		
	%put the denominator is  &amp;amp;denom. yay this macro worked;
	
		
proc means data=derived._01_esrd mean median  Q1 Q3;
	var age  enrol_dur;
	output out=stat_age mean()= median()= STD()= Q1()= Q3()= Min()= Max()=/autoname; 
run;

/*DEMO TABLE WITHOUT MACROS*/
proc sql ;
	create table _02_demo as 
	select 1 as seq, "Total Cohort" as col, 	N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where enrolid 		union 
	select 2 as seq, "Gender" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where not enrolid 	union 
	select 3 as seq, "Female" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where sex='2' 		union 
	select 4 as seq, "Male" as col, 		N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where sex='1' 		union 
	select 5 as seq, "Type of Dialysis" as col, 	N(enrolid) as N, N(enrolid)/&amp;amp;denom. as percent 		from derived._01_esrd 	where not enrolid 	union 
	select 6 as seq, "age" as col, 			age_mean as N, age_median as percent 			from stat_age 			 		union 
	select 7 as seq, "Enrollment Duration" as col, 	enrol_dur_mean as N, enrol_dur_median as percent	from stat_age 			  
;
quit ;

%mend denom; 
%denom ;

ods csv file  = "/data1/projects/yellow/YVM0002aq/output/demo.csv" ;

	proc print data =_02_demo ;
	run ;
	
ods csv close ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what my actual code looks like after alterations. I want a MACROS for the numbers as seq and for the where condition as parameters&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 19:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479224#M286469</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-18T19:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479250#M286470</link>
      <description>&lt;P&gt;But does this code actually run and produce usable results?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 20:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479250#M286470</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-18T20:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: sas macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479269#M286471</link>
      <description>&lt;P&gt;You haven't really shared much about your data.&lt;/P&gt;
&lt;P&gt;Here is a similar set of tables using one of the SAS supplied data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.class;
   class sex age;
   var height weight;
   table all='Total' sex ,
         age * n=' '
   ;
   table height weight,
         mean median qrange='IQR' q1 q3
   ;
run;&lt;/PRE&gt;
&lt;P&gt;There are lots of appearance options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 20:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-macros/m-p/479269#M286471</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-18T20:47:22Z</dc:date>
    </item>
  </channel>
</rss>

