Looks like the macro also doesn't accept a data step view as suggested by Reeza.
Below fully working sample code that demonstrates how you can prepare the data.
data have;
infile datalines dsd dlm=',' truncover;
input DEM_AGE DEM_SEX cohort_flag TM_group;
datalines;
3,1,1,0
2,1,1,1
3,2,1,1
3,2,1,1
3,2,1,0
2,2,1,1
2,1,1,1
3,1,1,1
2,1,1,1
3,2,1,0
2,1,1,0
2,2,1,1
3,2,1,0
2,2,0,
3,2,1,1
3,2,1,1
3,1,1,0
3,2,1,0
2,1,1,0
3,1,1,1
3,2,1,1
3,2,1,0
3,2,1,1
3,2,1,1
3,2,1,1
;
RUN;
proc format library=temp;
value age2grp
1='1:Age Group <65'
2='2:Age Group [65,75)'
3='3:Age Group >=75'
.='Inapplicable/Missing'
;
value sex
1='1:Male'
2='2:Female'
.='Inapplicable/Missing'
;
value yesfmt
1='1:Yes'
2='2:No'
.='Inapplicable/Missing'
;
RUN;
filename tableN url 'https://communities.sas.com/kntur85557/attachments/kntur85557/library/4477/5/tablen_05102022.sas';
/*filename tableN url 'https://communities.sas.com/kntur85557/attachments/kntur85557/library/4477/5/tablen_032020_pharmasug.sas';*/
/*filename tableN url 'https://gist.githubusercontent.com/statgeek/b55d964c99975c2ba23fa771afe616bc/raw/b30d55caf6ec4028f5afed3b260ce86b50419ddb/tablen.sas';*/
%include tableN /source2;
data cohort_1;
set have;
where cohort_flag=1;
run;
%tablen(
data=cohort_1
,by=TM_group
,var=DEM_AGE DEM_SEX
,type=2 2
,outdoc=C:\temp\test.rtf
);
@Wolverine wrote:
4189 %tablen(data=temp.fall_summ_allyrs_cohort by TM_group, 4190 var = DEM_SEX DEM_AGE, 4191 type= 2 2, outdoc="C:\Users\XXXXXXXX\test.rtf"; 4192 RUN;
There is no need for a RUN statement, but the closing parenthesis of the macro call must not be replaced by a semicolon.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.