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 .
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 .
Have you looked into or tried a RETAIN.?
retain newVar;
if not missing(product) then newVar = Product;
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.
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.
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 .
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.