BookmarkSubscribeRSS Feed
NazaninSAS
Quartz | Level 8

Hi,

This is my code.

/* NATIONAL Abor*/

proc report data=work.WFA

nowd;

columns EEOG NOC CMA PRI Abor Aborprc LMAAbor Expected Gap;

define EEOG / group 'EEOG' left;

define NOC/ group 'NOC' left;

define CMA / group 'CMA' left;

define PRI/ analysis n format=comma8. '# of Employees ' center;

define Abor/analysis n format=comma8. '# of Abor' center;

define Aborprc / computed format=percent8.1 'Abor(%)'center;

 

compute Aborprc;

AborPRC= Abor.n/PRI.n;

endcomp;

 

rbreak after / dol skip summarize style=Header{fontweight=bold};

 

 compute after;

EEOG= "Total";

endcomp

run;

 

EEOG has different values, I want to customize my code to drop certain variables based on each EEOG. For example, if EEOG is 2, I want to drop NOC and CMA, but if EEOG is 3, I only want to drop CMA.

 

is there any way of coding this?

 

Thanks,

Nazanin

11 REPLIES 11
Reeza
Super User

You can't conditionally 'drop' variables. You can set it to missing, but I would recommend doing that in a previous step. Not 100% sure this will give you want you want. If not, post back more details, specifically an example of what you're getting and what you want instead.

 

data wfa2;
set wfa;

if eeog=2 then call missing(noc, cma);
if eeog=3 then call missing(cma);

run;


@NazaninSAS wrote:

Hi,

This is my code.

/* NATIONAL Abor*/

proc report data=work.WFA

nowd;

columns EEOG NOC CMA PRI Abor Aborprc LMAAbor Expected Gap;

define EEOG / group 'EEOG' left;

define NOC/ group 'NOC' left;

define CMA / group 'CMA' left;

define PRI/ analysis n format=comma8. '# of Employees ' center;

define Abor/analysis n format=comma8. '# of Abor' center;

define Aborprc / computed format=percent8.1 'Abor(%)'center;

 

compute Aborprc;

AborPRC= Abor.n/PRI.n;

endcomp;

 

rbreak after / dol skip summarize style=Header{fontweight=bold};

 

 compute after;

EEOG= "Total";

endcomp

run;

 

EEOG has different values, I want to customize my code to drop certain variables based on each EEOG. For example, if EEOG is 2, I want to drop NOC and CMA, but if EEOG is 3, I only want to drop CMA.

 

is there any way of coding this?

 

Thanks,

Nazanin


 

NazaninSAS
Quartz | Level 8

Thanks Reeza,

 

basically, I want o run the code and in the output, I want to drop columns based on EEOG

these are my columns for the whole report:

columns EEOG NOC CMA PRI Abor Aborprc;

but based on the table below, I don't need to see NOC or CMA for EEOG02. or for EEOG 03, I just want the breakdown by NOC. and so on.

 

EEOG

NOC

CMA

# of Employees

# of Abor

Abor(%)

2

No

No

   

3

Yes

No

   

5

No

yes

   

 

another way I think is writing different codes for different EEOGs and then append them together to have the total.

 

Thanks,

 

Nazanin

Reeza
Super User
So how does that look for EEOG 2 and 3? I'm not understanding how you'd drop them from the overall table, or are you expecting separate tables?
NazaninSAS
Quartz | Level 8

something like this:

EEOG

NOC

CMA

# of Employees

# of Abor

Abor(%)

2

  

213

20

1.4%

3

1111

 

1

6.7%

1.3%

 

1112

 

2

0

0.0%

 

1114

 

7

0

0.0%

 

1121

 

11

0

0.0%

      

5

 

Winnipeg

   
 TOTAL  

42,102

1,343

3.2%

 

For EEOG 02, I don not need any further breakdown, but for EEOG o3, I want the breakdown by NOC, EEOG05, I want the breakdown by CMA.

 

 

Thanks,

 

Nazanin

Reeza
Super User
I think CALL MISSING() as I suggested will work for that.
NazaninSAS
Quartz | Level 8

Hi,

 

I did call missing:

data WFA2;

set WFA;

if EEOG=2 then call missing(NOC,CMA);

if EEOG=3 then call missing(CMA);

if EEOG=5 then call missing ( NOC);

run;

 

but my output, totally eliminated EEOG02, 03, and 05.

I want o keep them , but I don't want to see NOC and CMA for them.

 

Thanks,

Nazanin

Reeza
Super User
What did the rest of your code look like? If you had other measures I'm surprised those didn't get included.
NazaninSAS
Quartz | Level 8

/* NATIONAL Abor*/

proc report data=work.WFA

nowd;

columns EEOG NOC CMA PRI Abor Aborprc ;

define EEOG / group 'EEOG' left;

define NOC/ group;

define CMA/ group;

define PRI/ analysis n format=comma8. '# of Employees ' center;

define Abor/analysis n format=comma8. '# of Abor' center;

define Aborprc / computed format=percent8.1 'Abor(%)'center;

 

compute Aborprc;

 

 

AborPRC= Abor.n/PRI.n;

endcomp;

compute Expected;

 

compute after;

 

EEOG= "Total";

endcomp;

compute after EEOG;

line '';

endcomp;

break after EEOG / dol skip summarize style=Header{fontweight=bold};

footnote "Source, CAS";

run;

 

 

just out of curiosity, can I write a "compute" to call another "proc report" ?

 

Thanks,

Nazanin

Reeza
Super User
You still pointed it to the WFA data set, not the new one....
NazaninSAS
Quartz | Level 8

no,

I did it to the new one. I also went and changed the data set manually to see if it worked. but as soon as I delete them, the whole EEOG does not show up in the output.

I will run it again, and I will let you know.

 

Thanks,

 

Nazanin

NazaninSAS
Quartz | Level 8

Thanks Reeza,

 

Finally, I found it! I have to use "call missing" as you said before the proc report, but in proc report, when I define variables, I have to use  " group" "missing" instead of  just "group".

for example:

define NOC/ group missing;

 

but before I use:

 

define NOC/ group;

 

 

best regards,

Nazanin

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 3492 views
  • 2 likes
  • 2 in conversation