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

Hello everyone,

I am working on exporting data to an Excel file using the ODS EXCEL feature in SAS. Along with the data, I need to add a credential (e.g., a code) to a specific cell, say M1.

Here is a sample code snippet that I am using:

 

/* Sample data */
data sample_data;
    input Name $ Age Gender $ Salary;
    datalines;
    John 30 M 50000
    Jane 25 F 55000
    Sam 28 M 48000
    Lisa 35 F 62000
    ;
run;

/* Export data to Excel using ODS EXCEL */
ods excel file="sample_data.xlsx" options(protect_worksheet='yes');

proc report data=sample_data;
quit;

ods excel options(sheet_interval="none" start_at="M1");

proc odstext;
  p "78YKJXX22";
run;

ods excel close;

I want like 

 

Daily1_0-1720160821392.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User


Ksharp_0-1720167722490.png

 

 

/* Sample data */
data sample_data;
infile datalines truncover;
    input Name $ Age Gender $ Salary  (a1-a8 M) ($);
label  M='78YKJXX22'
       a1='*' a2='*' a3='*' a4='*' a5='*' a6='*' a7='*' a8='*';
    datalines;
    John 30 M 50000
    Jane 25 F 55000
    Sam 28 M 48000
    Lisa 35 F 62000
    ;
run;


%let excel= c:\temp\sample_data.xlsx ;




ods _all_ close;
/* Export data to Excel using ODS EXCEL */
ods excel file="&excel." options(protect_worksheet='yes' sheet_name='Sheet1') ;
proc report data=sample_data nowd split='*';
define a1-a8/display style={background=cxFAFBFE foreground=cxFAFBFE bordercolor=cxFAFBFE};
define M/display style={background=cxFAFBFE foreground=black bordercolor=cxFAFBFE};
run;;

ods excel close;

 

View solution in original post

4 REPLIES 4
Ksharp
Super User


Ksharp_0-1720167722490.png

 

 

/* Sample data */
data sample_data;
infile datalines truncover;
    input Name $ Age Gender $ Salary  (a1-a8 M) ($);
label  M='78YKJXX22'
       a1='*' a2='*' a3='*' a4='*' a5='*' a6='*' a7='*' a8='*';
    datalines;
    John 30 M 50000
    Jane 25 F 55000
    Sam 28 M 48000
    Lisa 35 F 62000
    ;
run;


%let excel= c:\temp\sample_data.xlsx ;




ods _all_ close;
/* Export data to Excel using ODS EXCEL */
ods excel file="&excel." options(protect_worksheet='yes' sheet_name='Sheet1') ;
proc report data=sample_data nowd split='*';
define a1-a8/display style={background=cxFAFBFE foreground=cxFAFBFE bordercolor=cxFAFBFE};
define M/display style={background=cxFAFBFE foreground=black bordercolor=cxFAFBFE};
run;;

ods excel close;

 

Daily1
Quartz | Level 8

I am currently working with SAS and I need to generate an Excel file with a specific sheet that is protected by a password. I know how to use ODS to create Excel files, but I’m unsure how to set a password to protect a sheet within the file. Could someone provide an example of how to do this?

PaigeMiller
Diamond | Level 26

@Daily1 wrote:

I am currently working with SAS and I need to generate an Excel file with a specific sheet that is protected by a password. I know how to use ODS to create Excel files, but I’m unsure how to set a password to protect a sheet within the file. Could someone provide an example of how to do this?


Please start a new thread for this.

--
Paige Miller
Ksharp
Super User
Nope.
If I was right, SAS is unable to set a password on a excel file, you need resort to VBA .
or maybe @Cynthina_sas knew something I don't know.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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
  • 1128 views
  • 0 likes
  • 3 in conversation