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

Hi All ,

I have an input file :

For PRODUCT1 61 Total Exceptions Were Found            
For PRODUCT1 8  Exceptions Were ignored                
For PRODUCT1 32 Total Baseline Violations Were Found   
--------------------------------------------------------
PRODCHK  For  : PRODUCT1                               
                                                       
DATE: 17 Sep 2018  TIME: 00:10:08                      
========================================================
Object     : SAMPLE1                          
Type       : FLAT                                      
Attribute  : 56                                        
Should_Be  : TESTED                                    
Actual     : TESTED                                    
Baseline   : NO                                        
===========================================            
===========================================            
Object     : SAMPLE2                          
Type       : FLAT                                      
Attribute  : 22                                        
Should_Be  : TESTED                                    
Actual     : NONTESTED                                 
Baseline   : YES                                       
===========================================            
===========================================            
Object     : SAMPLE3                          
Type       : OVAL                                      
Attribute  : 32                                        
Should_Be  : TESTED                                    
Actual     : TESTED                                    
Baseline   : NO                                        
===========================================            
===========================================      

 

I used to _infile_ to read the records and produce an output like

 

Product     Object        Type     Attribute     Should_Be     Actual     Baseline
                                                                              
Product1                                                                          
                 SAMPLE1   FLAT 56                 TESTED        TESTED      NO             
                 SAMPLE2   FLAT 22                 NONTESTED TESTED    NO 
                 SAMPLE3   OVAL 32                TESTED          TESTED YES   

 

In the output product1 is coming in the first row . My requirement is product 1 should come before all 3 observations . Like

 

Product     Object        Type     Attribute     Should_Be     Actual  Baseline

Product1         SAMPLE1      FLAT 56   TESTED   TESTED NO            
Product1         SAMPLE2      FLAT 22   NONTESTED      TESTED NO 
Product1         SAMPLE3      OVAL 32  TESTED       TESTED YES   

 

Shall I write two separate DATA statement and then two to perform a one to many merge . Infact I tried that but merge is quite complex . I could able to assign product1 to a variable called ProductValue, but not sure how to append it at the beginning of each observation  .

 

Thanks .

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can easily do that in PROC REPORT using a COMPUTE statement with a GROUP variable, once you manage to get it in the correct location in your data set, which was your original question. Has that been resolved?

If yes, here's an example from a previous question a few weeks ago.

 

data test;
infile cards truncover;
input GROUP_VAR $ brand $ Freq Freq1 COUNT;
datalines;      
SUB1 A 2 3 8
SUB1 B 3 5 4
SUB1 C 4 6 2
SUB2 D 5 1 1
SUB2 E 6 5 8
SUB2 F 7 7 9
;
run;

proc tabulate data=test;
class group_var brand / order=data missing;
var freq freq1 count;
table group_var=''*brand='', freq*sum='' freq1*sum='' count*sum=''/misstext='';
run;

proc report nowd data=test;
   col group_var brand freq freq1 count;
   define group_var / group noprint format=$8.;
   define brand/order;
   define freq/ sum;
   define freq1 / sum;
   define count / sum;
  break before group_var  / skip;
    compute before group_var/
      style={cellheight=8pt font_size=12pt just=left};
      line group_var $100.;
  endcomp;
run;

@sams54156 wrote:
Hi Astounding ,
Thanks for the reply . Yes I my program is Producing output like
Product Object Type Attribute Should_Be Actual Baseline

Product1
SAMPLE1 FLAT 56 TESTED TESTED NO
SAMPLE2 FLAT 22 NONTESTED TESTED NO
SAMPLE3 OVAL 32 TESTED TESTED YES

But I am still trying to produce an output like
Product Object Type Attribute Should_Be Actual Baseline

Product1 SAMPLE1 FLAT 56 TESTED TESTED NO
Product1 SAMPLE2 FLAT 22 NONTESTED TESTED NO
Product1 SAMPLE3 OVAL 32 TESTED TESTED YES

I am able to store “product1” in a variable but in proc print it gets printed as first observation instead I want its get printed before all observation not as a separate observation .



 

View solution in original post

5 REPLIES 5
Reeza
Super User

Have you looked into or tried a RETAIN.?

 

retain newVar;

if not missing(product) then newVar = Product;

 

Astounding
PROC Star

Are you able to produce a SAS data set that looks like this?  It takes some work to get:

 

Product     Object        Type     Attribute     Should_Be     Actual  Baseline

Product1         SAMPLE1      FLAT 56   TESTED   TESTED NO            
Product1         SAMPLE2      FLAT 22   NONTESTED      TESTED NO 
Product1         SAMPLE3      OVAL 32  TESTED       TESTED YES   

 

If you can do that much, then this is just a reporting problem and does have potential solutions.

sams54156
Calcite | Level 5
Hi Astounding ,
Thanks for the reply . Yes I my program is Producing output like
Product Object Type Attribute Should_Be Actual Baseline

Product1
SAMPLE1 FLAT 56 TESTED TESTED NO
SAMPLE2 FLAT 22 NONTESTED TESTED NO
SAMPLE3 OVAL 32 TESTED TESTED YES

But I am still trying to produce an output like
Product Object Type Attribute Should_Be Actual Baseline

Product1 SAMPLE1 FLAT 56 TESTED TESTED NO
Product1 SAMPLE2 FLAT 22 NONTESTED TESTED NO
Product1 SAMPLE3 OVAL 32 TESTED TESTED YES

I am able to store “product1” in a variable but in proc print it gets printed as first observation instead I want its get printed before all observation not as a separate observation .


Astounding
PROC Star

There's a bit of a learning curve involved, but it looks like you may want to investigate a very old style of reporting ... a DATA step that uses FILE and PUT statements.  If you are searching the literature it is usually called "customized reporting".

 

The overall form of the program would be:

 

data _null_;

set have;

by product1;

file print header=pagetop;

if first.product1 then do;

   put ..........................;

end;

put .............;

return;

pagetop:

put ......................;

return;

run;

 

Details abound.  But the DATA step gives you pretty much complete control over every piece of text and its location.

Reeza
Super User

You can easily do that in PROC REPORT using a COMPUTE statement with a GROUP variable, once you manage to get it in the correct location in your data set, which was your original question. Has that been resolved?

If yes, here's an example from a previous question a few weeks ago.

 

data test;
infile cards truncover;
input GROUP_VAR $ brand $ Freq Freq1 COUNT;
datalines;      
SUB1 A 2 3 8
SUB1 B 3 5 4
SUB1 C 4 6 2
SUB2 D 5 1 1
SUB2 E 6 5 8
SUB2 F 7 7 9
;
run;

proc tabulate data=test;
class group_var brand / order=data missing;
var freq freq1 count;
table group_var=''*brand='', freq*sum='' freq1*sum='' count*sum=''/misstext='';
run;

proc report nowd data=test;
   col group_var brand freq freq1 count;
   define group_var / group noprint format=$8.;
   define brand/order;
   define freq/ sum;
   define freq1 / sum;
   define count / sum;
  break before group_var  / skip;
    compute before group_var/
      style={cellheight=8pt font_size=12pt just=left};
      line group_var $100.;
  endcomp;
run;

@sams54156 wrote:
Hi Astounding ,
Thanks for the reply . Yes I my program is Producing output like
Product Object Type Attribute Should_Be Actual Baseline

Product1
SAMPLE1 FLAT 56 TESTED TESTED NO
SAMPLE2 FLAT 22 NONTESTED TESTED NO
SAMPLE3 OVAL 32 TESTED TESTED YES

But I am still trying to produce an output like
Product Object Type Attribute Should_Be Actual Baseline

Product1 SAMPLE1 FLAT 56 TESTED TESTED NO
Product1 SAMPLE2 FLAT 22 NONTESTED TESTED NO
Product1 SAMPLE3 OVAL 32 TESTED TESTED YES

I am able to store “product1” in a variable but in proc print it gets printed as first observation instead I want its get printed before all observation not as a separate observation .



 

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