BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jcis7
Pyrite | Level 9

G'day!

 

I'm stuck.  I don't know why I'm getting '.' in my output.

When I remove year as the across variable, sas is computing pctvar1 fine (I wanted to check if it was the compute block that was off).

 

I've the following data and code.

 

 

 

data new;
infile DATALINES dsd missover;
input county $ facility $ total var1 year $;
CARDS;
countya, busybeez, 100, 99, 20012002
countya, childtime, 90, 90, 20012002
countyb,  kidzplace, 3, 2 , 20012002
countyb, littlesprouts, 2, 2, 20012002
countya, busybeez, 98, 98, 20022003
countya, childtime, 99, 99, 20022003
countyb,  kidzplace, 5, 4 , 20022003 
countyb, littlesprouts, 2, 2, 20022003
;
run;

title 'Var1 by county by year';
proc report data=new out=want nowd  missing completerows ;
  column county
         total var1 
         pctvar1,year; 
            
  define county / group
                  'County'; 
  define year /  display across
                        'Year'; 
  define total / analysis sum noprint ; 

  define var1 / analysis noprint;
  define pctvar1 / computed 
                     'Pct Var1'
                     format=percent7.1;
  compute pctvar1; 
         pctvar1=var1.sum/total.sum; 
  endcompute;

run;

 When I run it, I'm getting this output:

 

Var1 by county by year

 

 

Pct Var1

 

Year

County

20012002

20022003

countya

.

.

countyb

.

.

 

 

My desired output is:

 

 

Pct Var1

 

Year

County

20012002

20022003

countya

  99.4

 100.0

countyb

  80.0

   85.7

 

 

 

Log:

 

 

538

539  data new;

540  infile DATALINES dsd missover;

541  input county $ facility $ total var1 year $;

542  CARDS;

 

NOTE: The data set WORK.NEW has 8 observations and 5 variables.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.01 seconds

 

 

551  ;

552  run;

553

554  title 'Var1 by county by year';

555  proc report data=new out=want nowd  missing completerows ;

556    column county

557           total var1

558           pctvar1,year;

559

560    define county / group

561                    'County';

562    define year /  display across

563                          'Year';

564    define total / analysis sum noprint ;

565

566    define var1 / analysis noprint;

567    define pctvar1 / computed

568                       'Pct Var1'

569                       format=percent7.1;

570    compute pctvar1;

571           pctvar1=var1.sum/total.sum;

572    endcompute;

573

574  run;

 

NOTE: There were 8 observations read from the data set WORK.NEW.

NOTE: The data set WORK.WANT has 2 observations and 6 variables.

NOTE: PROCEDURE REPORT used (Total process time):

      real time           0.10 seconds

      cpu time            0.01 seconds

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jcis7
Pyrite | Level 9

Thanks!  Works!

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

title 'Var1 by county by year';
proc report data=new out=want nowd  missing completerows ;
  column county
          
        year,(total var1  pctvar1);  
            
  define county / group
                  'County'; 
  define year /  display across
                        'Year'; 
  define total / analysis sum noprint ; 

  define var1 / analysis sum noprint;
  define pctvar1 / computed 
                     'Pct Var1'
                     format=percent7.1;
  compute pctvar1; 
      _c4_=_c3_/_c2_; 
      _c7_=_c6_/_c5_; 
  endcompute;

run;
jcis7
Pyrite | Level 9

Thanks!  Works!

 

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 933 views
  • 0 likes
  • 2 in conversation