Hi all,
I have two datasets which have labels as below
When I try to compare both these datasets, the label comparison section is not coming up as shown below,
Does anyone know how to solve this?
Are you sure you have labels for the datasets compared?
For me it works:
What if you do a PROC CONTENTS?
In the very first output table (Results) ... do you see your label?
Ciao,
Koen
per the doc:
Note: The COMPARE procedure omits data set labels if the line size is too small for them.
I guess you have an enormous lot of trailing blanks in your label ! Please trim the label!
[EDIT] ... or augment the line size with the linesize option.
Cheers,
Koen
I even tried using a different dataset, and also set the linesize=256. But still no change.
@ballardw @Tom @Kathryn_SAS @sbxkoenk
For your information, I'm running this procedure inside a clinical study, so is there anything that suppresses this label? Because when I run using sashelp.class dataset, i can see the labels.
Can you send a PROC CONTENTS of each data set? Can you run the following as a test to see if you see the labels?
proc contents data=adam.adlb;
run;
proc contents data=qcadam.adlb;
run;
data one(label='HH');
x=1;
run;
data two(label='Demographics');
x=2;
run;
options label linesize=256;
proc compare base=one compare=two;
run;
i can see the labels when i run this code, but why can't i see that directly from the library? Below is the output from content porcedure. Both datasets showed same label, but i'm keeping here only one
Which output destination are you using? Please send your log so that we can see the exact code you are running and add the following before the PROC COMPARE step:
proc options option=linesize;
run;
How long are your actual labels? And your dataset names since they are both displayed on the same line in the PROC COMPARE output.
You can use the ATTRC() function as I showed to check if your labels have been defined with multiple trailing spaces. If doing it in data step it takes a little work to notice the trailing spaces.
data test1(label='NoTrailing')
test2(label='Trailing ')
;
x=1;
run;
data check;
length memname $32 len lenn 8 label $300 ;
do memname='test1','test2';
dsid=open(memname);
label=quote(attrc(dsid,'label'));
len=length(dequote(label));
lenn=lengthn(translate(dequote(label),'.',' '));
dsid=close(dsid);
output;
end;
drop dsid;
run;
data _null_;
set check;
put (memname len lenn label) (=);
run;
Results show that the trailing spaces are actually stored in the metadata of the dataset.
memname=test1 len=10 lenn=10 label="NoTrailing" memname=test2 len=8 lenn=10 label="Trailing "
thank you @Tom
when i checked the length using your code, i found that the trailing space are more than what is apparent in the proc contents
Do you know how to trim this, because in proc sql i'm not adding any space.
The code in your second picture will not add any spaces to the end of the label in for the dataset DM.
What I suspect you are doing is trying to use some metadata to generate the code. So perhaps you have a dataset with MEMNAME and MEMLABEL and you are using it to generate that code with LABEL= dataset option.
If you use macro variables to generate the code.
&dsname(label="&dslabel")
Then make sure that the macro variables do not have trailing spaces in them. So make sure to use CALL SYMPUTX() instead of the ancient CALL SYMPUT(). NOTE: You should only be using CALL SYMPUT() if it is important to include leading/trailing spaces in the generated macro variables.
call symputx('dsname',memname);
call symputx('dslabel',memlabel);
Or if you are using SQL use the TRIMMED keyword.
select memname,memlabel
into :dsname trimmed
, :dslabel trimmed
from ...
If you use a data step to write the code to a file then make sure not to write the trailing spaces.
put memname '(label=' memlabel :$quote. ')' ;
Also you might want to use the QUOTE() function to add the quotes. That way you can use the optional second parameter so that the value is quoted using single quotes so that any % or & characters in the member label are not acted on by the macro processor.
call symputx('dslabel',quote(trim(memlabel),"'"));
...
&dsname(label=&dslabel)
...
NOTE: It is also possible that the metadata used to generate the label has other invisible characters instead of spaces. So check that also. Common things to check for are tabs ('09'x) and non-breaking spaces ('A0'x). Or end of line characters carriage return ('0D'x) or line feed ('0A'x).
memlabel=translate(memlabel,' ','09A00D0A'x);
You can check the current Linesize and then increase it.
proc options option=linesize;
run;
options linesize=120;
Check your LINESIZE setting.
With LINESIZE set to 132 (normal line printer carriage length) it will display labels up to 72 bytes long.
73 %put linesize=%sysfunc(getoption(ls)); linesize=132 74 data one(label='First') two(label="%substr(%sysfunc(repeat(Second,20)),1,72)"); 75 set sashelp.class; 76 run;
NOTE: PROC COMPARE (or perhaps the actual way that labels are stored in the SAS dataset) treats trailing spaces differently than the rest of SAS treats them.
73 data test1(label='NoTrailing')
74 test2(label='Trailing ')
75 ;
76 x=1;
77 run;
NOTE: The data set WORK.TEST1 has 1 observations and 1 variables.
NOTE: The data set WORK.TEST2 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
78
79 %let dsn=test1;
80 %let dsid=%sysfunc(open(&dsn,i));
81 %put &=dsn LABEL="%sysfunc(attrc(&dsid,label))";
DSN=test1 LABEL="NoTrailing"
82 %let dsn=test2;
83 %let dsid=%sysfunc(open(&dsn,i));
84 %put &=dsn LABEL="%sysfunc(attrc(&dsid,label))";
DSN=test2 LABEL="Trailing "
85 %let dsid=%sysfunc(close(&dsid));
So if you are defining the labels using quoted strings make sure not to include the trailing spaces.
If you are creating macro variables to generate the LABEL then take care not to add trailing spaces into the macro variable.
For what very little it may be worth, I tend to create output data sets for Proc Compare and then write a custom report for anything except nearly trivial Proc Compare output because the procedure is quite often not very nice. With a data set then I can use all of the options provided by Proc Print or Report to make sure the appearance is as desired.
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.