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

Hello,

 

I have tried this SAS code but I forgot to mentioned that it is inside of a macro function and the options label seems not working properly.  How to solve that issue.

 

options label;
Data BANDE4.&CO._AUTO_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE1.&CO._AUTO_PRM&MOISC.&YEAR. ;
run;

/****** Bande2 for Property *****/
options label;
Data BANDE5.&CO._PROP_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE2.&CO._PROP_PRM&MOISC.&YEAR. ;
run;

/****** Bande3 for Enterprise *****/
options label;
data BANDE6.&CO._CNA_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE3.&CO._CNA_PRM&MOISC.&YEAR. ;
run;
proc compare base=bande1.&CO._AUTO_PRM&MOISC.&YEAR. compare=BANDE4.&CO._AUTO_PRM&MOISC.&YEAR. 
listvar;
/*attrib _all_ label=' '; */
run;
proc compare base=bande2.&CO._prop_PRM&MOISC.&YEAR. compare=BANDE5.&CO._prop_PRM&MOISC.&YEAR. 
listvar; 
/*attrib _all_ label=' ';*/
run;
proc compare base=bande3.&CO._CNA_PRM&MOISC.&YEAR.  compare=BANDE6.&CO._CNA_PRM&MOISC.&YEAR.  
listvar; 
/*attrib _all_ label=' ';*/
run;
proc compare base=bande1.&CO._AUTO_PRM&MOISC.&YEAR. compare=BANDE4.&CO._AUTO_PRM&MOISC.&YEAR. 
listvar;
/*attrib _all_ label=' '; */
run;
proc compare base=bande2.&CO._prop_PRM&MOISC.&YEAR. compare=BANDE5.&CO._prop_PRM&MOISC.&YEAR. 
listvar; 
/*attrib _all_ label=' ';*/
run;
proc compare base=bande3.&CO._CNA_PRM&MOISC.&YEAR.  compare=BANDE6.&CO._CNA_PRM&MOISC.&YEAR.  
listvar; 
/*attrib _all_ label=' ';*/
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

When you change a system option using the OPTION statement it stays that way until you run another OPTION statement to change it.  It does not matter whether the option statement is part of your open code program or is generated by a macro you have run.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You haven't explained what is wrong with the code.

--
Paige Miller
alepage
Barite | Level 11

Hello,

 

When the macro function %premiumc is executed, it read a .dat file to create three sas datasets, one for auto, one for property and another one for enterprise. (refer to bande1, bande2, bande3).

 

Here's the various libname and macro variables:

 

libname  BANDE1 spde '/.../Temp/Alain/test/Classic/gc/auto';
libname  BANDE2 spde '/.../Temp/Alain/test/Classic/gc/habi';
libname  BANDE3 spde '/.../Temp/Alain/test/Classic/gc/entr';

libname  BANDE4 spde '/.../Temp/Alain/test/Classic/gc2/auto';
libname  BANDE5 spde '/.../Temp/Alain/test/Classic/gc2/habi';
libname  BANDE6 spde '/.../Temp/Alain/test/Classic/gc2/entr';

filename TX1   '/.../pa.pxp4xax.sep4tuac.mo1.dat' lrecl=2000 recfm=v;
%LET MOISC =fev;
%LET YEAR =2025;
%let co=gc;

Then we have the macro function 

%macro premiumc;

...

%mend premiumc;

%premiumc;

 

Into that existing macro function, some SAS code at the end (but inside the macro function) the following SAS code:

 


/****** Bande1 for Auto *****/
options label;
Data BANDE4.&CO._AUTO_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE1.&CO._AUTO_PRM&MOISC.&YEAR. ;
run;
/****** Bande2 for Property *****/
options label;
Data BANDE5.&CO._PROP_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE2.&CO._PROP_PRM&MOISC.&YEAR. ;
run;
options label;
data BANDE6.&CO._CNA_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE3.&CO._CNA_PRM&MOISC.&YEAR. ;
run;
proc compare base=bande1.&CO._AUTO_PRM&MOISC.&YEAR. compare=BANDE4.&CO._AUTO_PRM&MOISC.&YEAR. 
listvar;
/*attrib _all_ label=' '; */
run;
proc compare base=bande2.&CO._prop_PRM&MOISC.&YEAR. compare=BANDE5.&CO._prop_PRM&MOISC.&YEAR. 
listvar; 
/*attrib _all_ label=' ';*/
run;
proc compare base=bande3.&CO._CNA_PRM&MOISC.&YEAR.  compare=BANDE6.&CO._CNA_PRM&MOISC.&YEAR.  
listvar; 
/*attrib _all_ label=' ';*/
run;


So after reading the .dat file, three sas datasets are created respectively into bande1, bande2, and bande3.

Thereafter, I read those datasets and I had the variable ORGNL_SAS_DS_ROW_NBR into the three datasets but the updated datsets are saved in band4, bande5 and bande6 respectively.

After that, a proc compare is done comparing the dataset in bande1, bande2 and bande3 with those in bande4, bande5 and bande6.

 

The issue we have is with the label values. When we compare the values of bande1 and bande4 sas said that they are diffent which is not the case and the label value for bande5 and bande6 are black even if we use the options label (see the sas code options label;

data...

ORGNL_SAS_DS_ROW_NBR=_N_;

set...

run;

 

alepage_0-1742997469171.png

 

 

alepage_1-1742997527965.png

 

 

alepage_2-1742997590007.png

 

When we select just the following line of code and execute it , it works fine.
How to solve that issue?

/****** Bande1 for Auto *****/
options label;
Data BANDE4.&CO._AUTO_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE1.&CO._AUTO_PRM&MOISC.&YEAR. ;
run;

/****** Bande2 for Property *****/
options label;
Data BANDE5.&CO._PROP_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE2.&CO._PROP_PRM&MOISC.&YEAR. ;
run;

/****** Bande3 for Enterprise *****/
options label;
data BANDE6.&CO._CNA_PRM&MOISC.&YEAR. ;
ORGNL_SAS_DS_ROW_NBR=_N_;
set BANDE3.&CO._CNA_PRM&MOISC.&YEAR. ;
run;

proc compare base=bande1.&CO._AUTO_PRM&MOISC.&YEAR. compare=BANDE4.&CO._AUTO_PRM&MOISC.&YEAR.
listvar;
/*attrib _all_ label=' '; */
run;
proc compare base=bande2.&CO._prop_PRM&MOISC.&YEAR. compare=BANDE5.&CO._prop_PRM&MOISC.&YEAR.
listvar;
/*attrib _all_ label=' ';*/
run;
proc compare base=bande3.&CO._CNA_PRM&MOISC.&YEAR. compare=BANDE6.&CO._CNA_PRM&MOISC.&YEAR.
listvar;
/*attrib _all_ label=' ';*/
run;

alepage_3-1742998492603.png

 

 

 

 

 

 

SASKiwi
PROC Star

An OPTIONS LABEL statement works the same in a macro as outside. Try this test;

%macro test (option=);

options &option;

data cars;
  count = _n_;
  set sashelp.cars;
run;

proc contents data = cars  details;
run;

%mend test;

%test(option = nolabel);
%test(option = label);

If your macro behaves differently then you will need to post a complete example that demonstrates the problem.

Tom
Super User Tom
Super User

When you change a system option using the OPTION statement it stays that way until you run another OPTION statement to change it.  It does not matter whether the option statement is part of your open code program or is generated by a macro you have run.

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1139 views
  • 0 likes
  • 4 in conversation