BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Patrick
Opal | Level 21

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.

Spoiler
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
  );
Reeza
Super User
Create a view of that data set and use it instead of trying to modify the macro.

data have_cohort1 /view=have_cohort1;
set have;
where cohort_flag=1;
run;

Then use the view in the macro call instead.
FreelanceReinh
Jade | Level 19

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 3497 views
  • 5 likes
  • 5 in conversation