BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JC411911
Obsidian | Level 7

Hello,

I have the below code which is part of larger code that will stop running the rest of the program if there is a difference in the proc compare. It is working okay but I am curious if there is a way to rename the _type_ variable that is created for the comparison. Right now it list BASE and COMPARE which is great but for a user that isn't aware I would like to rename to the actual file names. Is this possible?

JC411911_0-1715100668272.png

 

%let diff_count = 0;

/* Compare the TO_TAX and FROM_TAX BUWfiles */
PROC COMPARE BASE=WORK.TO_TAX_MODIFIED brief transpose COMPARE=WORK.FROM_TAX_MODIFIED OUT=COMPARISON OUTBASE OUTCOMP OUTDIF LISTOBS OUTNOEQUAL BRIEFSUMMARY;
    VAR member_number account_number payer_id ;
    title 'COMPARING FILE SENT AND RECEIVED FROM';
RUN;

DATA _NULL_;
    SET COMPARISON END=eof;
    IF eof THEN CALL SYMPUT('diff_count', _N_);
RUN;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Are asking how to make a COPY of the OUTPUT dataset from PROC COMPARE where you replace the values "BASE" and "COMPARE" in the variable _TYPE_ with the names of the datasets that were compared?

 

That should be simple, as long as you actually have the names.  In your example code the names are only in the CODE, they are not anywhere that a program could find them.  If you have the names in a macro variable for example.

 

%let base=TO_TAX_MODIFIED ;
%let compare=FROM_TAX_MODIFIED ;
proc compare base=&base compare=&compare out=COMPARISON .....
...

data COMPARISON ;
  length _type_ $41 ;
  set COMPARISON ;
  if _type_="BASE" then _type_="&base";
  if _type_="COMPARE" then _type_="&compare";
run;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Are asking how to make a COPY of the OUTPUT dataset from PROC COMPARE where you replace the values "BASE" and "COMPARE" in the variable _TYPE_ with the names of the datasets that were compared?

 

That should be simple, as long as you actually have the names.  In your example code the names are only in the CODE, they are not anywhere that a program could find them.  If you have the names in a macro variable for example.

 

%let base=TO_TAX_MODIFIED ;
%let compare=FROM_TAX_MODIFIED ;
proc compare base=&base compare=&compare out=COMPARISON .....
...

data COMPARISON ;
  length _type_ $41 ;
  set COMPARISON ;
  if _type_="BASE" then _type_="&base";
  if _type_="COMPARE" then _type_="&compare";
run;
JC411911
Obsidian | Level 7
Thank you simple enough. That gives me what I was needing. I guess my though was doing it in the proc compare step but seems like the base and compare observations are standard thus the need to create a separate data step to rename. Thank you
ballardw
Super User

First, which data set is this?

Are the "users" looking at the table view or a report generated from that data set?

 

Typically the response when related to "display a value" question is "use a format". Then either assign the format to the variable in a data set, which may have issues if you recreate the same format name, or use it to generate a report.

Something like:

data work.class;
   set sashelp.class;
   if name = 'Alice' then sex='M';
run;

PROC COMPARE BASE=sashelp.class brief transpose COMPARE=work.class OUT=work.COMPARISON OUTBASE OUTCOMP OUTDIF LISTOBS OUTNOEQUAL BRIEFSUMMARY;
RUN;

proc format library=work;
value $compbase
'BASE'='Sashelp.class'
'COMPARE'='Work.Class'
;
run;

/* modify the report data set to use the format*/
proc datasets library=work nodetails;
   modify Comparison;
   format _type_ $compbase.;
   run;
quit;

First make a data set with a difference to see the result.

Create the output and format, then assign that format to the dataset.

Or use a data step to add a variable with the name of the data set based on the value of _type_. The length of the _type_ variable is almost certainly going to be too short to accept many Library.datasetname values.

data work.final;
   set work.comparison;
   length setname $ 41;
   setname = put(_type_,$compbase.);
run;

This will have values like DIF in the Setname values by default as there is nothing in the format definition to change that. Or use If/then/else instead of a format.

The last may be preferred with shared data sets.

 

 

 

JC411911
Obsidian | Level 7
Thank you, this process works!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 593 views
  • 1 like
  • 3 in conversation