BookmarkSubscribeRSS Feed
cathy_sas
Calcite | Level 5

HI All,

I have a dataset with two group, suppose A & B.  But for some criteria, only one group is avaliable. i need to keep 0 for the other group on header count.

data have;

input var    group

crit1     A

crit1   B

crit2  B

crit3  A

crit3 B

;

run;

i need to only with criteria 2

My code:

data temp;

set have;

if var eq 'crit2';

run;

proc sql;

select count(distinct var) into :grp1 -:grp2 separated by ' '

group by group

;

quit;

later in report i am using those header count macro's in report header count

want :

categ                            A                 B

                                  N=&grp1(0)       N=&grp2(1)

crit2                             0                   1

but getting:

categ                            A                 B

                                  N=&grp1(1)       N=&grp2 (&grp2  (warning on log  &trt2 is not resolved)

  crit2                             0                   1

THanks

Cathy

4 REPLIES 4
PGStats
Opal | Level 21

I cannot reproduce your results. I get ERROR messages as soon as the SAS compiler hits the syntaxically incorrect " :grp1 -:grp2 separated by ' ' ". Please post code that runs OR the ERROR messages that the code generates.

PG

PG
cathy_sas
Calcite | Level 5

Hi,

I am also getting a warning while creating macro variable using proc sql.

Find the warning message below:

SYMBOLGEN:  Macro variable GRP1 resolves to 12

WARNING: Apparent symbolic reference GRP2 not resolved.

            %put &grp1 &grp2;

1 &grp2

In my above example. A is group1 & B is group2. For the criteria2 , i have only group2 , no group1.  so i need to show on my header count: group1(N=0)   & group2(N=1)

Thanks

Cathy

Jagadishkatam
Amethyst | Level 16

Please try , i did this by creating the dummy dataset

data have;

input var$    group$;

cards;

crit1     A

crit1   B

crit2  B

crit3  A

crit3 B

;

proc sort data=have out=dummy nodupkey;

by var;

run;

data dummy_;

  set dummy(keep=var);

  do group='A','B';

  output;

  end;

run;

data want;

merge have(in=a) dummy_;

by var group;

if a then cnt=1;

else cnt=0;

run;

proc sql;

select cnt into :grp1 -:grp2

from want where var='crit2';

quit;

%put &grp1 &grp2;

Thanks,

jag

Thanks,
Jag
Patrick
Opal | Level 21

As   answered, your code is not working. Below some working example. Not sure if this is what you're after.

As this is about getting the headers in reports for categories which are not in your data and depending on the Proc you're using an alternative approach could be to use "classdata" as documented here Base SAS(R) 9.4 Procedures Guide, Third Edition

I'm that there are other ways for other Proc's to create similar results.

data have;

  input var $ group $;

  datalines;

crit1 A

crit1 B

crit2 B

crit3 A

crit3 B

;

run;

%let grp1=0;

%let grp2=0;

proc sql;

  select count(distinct var) into :grp1 -:grp2

  from have

  where var eq 'crit2'

  group by group

  ;

quit;

%put &=grp1;

%put &=grp2;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1259 views
  • 0 likes
  • 4 in conversation