BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
Physician product year scripts
Mark Novo 2007 3000
Mark Novo 2007 4000
Mark Feib 2007 2500
Mark Novo 2008 2500
Twain Novo 2007 2000
Twain Novo 2008 3000
Twain Novo 2008 6000

How to generate the above data to following way ?


2007 2008
Physician Novo Feib Novo Feib
Mark 7000 2500 2500 -
Twain 2000 - 9000 -


The above can be achived using proc report.But I'm not able to get the prdoucts under year!
3 REPLIES 3
Cynthia_sas
Diamond | Level 26
Hi:
You could try:
[pre]
COLUMN year, product, scripts;
or
COLUMN scripts, year, product;
[/pre]

AND, in the DEFINE statements, both YEAR and PRODUCT would be ACROSS variables and SCRIPTS would be a SUM variable.

cynthia
SASPhile
Quartz | Level 8
> Hi:
> You could try:
> re]
> COLUMN year, product, scripts;
>
> COLUMN scripts, year, product;
> pre]
>
> AND, in the DEFINE statements, both YEAR and PRODUCT
> would be ACROSS variables and SCRIPTS would be a SUM
> variable.
>
> ynthia

Hi Cyhthia I tried this:

Physician product year scripts
Mark Novo 2007 3000
Mark Novo 2007 2000
Mark Feib 2007 2500
Mark Novo 2008 2500
Twain Novo 2007 2000
Twain Novo 2008 3000
Twain Novo 2008 4000


PROC REPORT DATA = novo_fieba NOWINDOWS HEADLINE;
COLUMN physician,year, product, scripts;
define physician/display;
DEFINE year / across;
DEFINE product/ across;
define scripts/sum;
run;

The idea is to display physician's name and in each year how much scripts for each product:

2007 2008
Physician Novo Feib Novo Feib
Mark 3000 2500 2500 -
Twain 2000 - 7000 -
Cynthia_sas
Diamond | Level 26
Hi:
No comma after physician:
[pre]
COLUMN physician year, product, scripts;
or
COLUMN physician scripts, year, product;

DEFINE physician / group;
DEFINE year / across;
DEFINE product / across;
DEFINE scripts / sum;
[/pre]

Sorry, my bad. I left physician out of the COLUMN statement.

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1060 views
  • 0 likes
  • 2 in conversation