Help using Base SAS procedures

Import Password Protected Text Files

Reply
Regular Contributor
Posts: 164

Import Password Protected Text Files

Hello

I have some data files that I would like to password protect for security reasons but still be able to import and manipulate in SAS.  Most of the data manipulations are summary of the stats so I'm not as worried about the security of the final data form.

Is this possible and how do I do it?  Thanks very much.

Valued Guide
Posts: 634

Re: Import Password Protected Text Files

If your 'data files' are SAS data sets, there are a series of data set options that can be used to provide various levels of password and/or encryption.  http://support.sas.com/documentation/cdl/en/ledsoptsref/63326/HTML/default/viewer.htm#n03k13diwk36x1...

Regular Contributor
Posts: 164

Re: Import Password Protected Text Files

Hi Art

I apologize because I didn't explain myself well.  I realize I can't password protect a .txt file so I guess I meant have in a zipped, password protected folder and extract from there.

Your post will be useful for when I have extracted the text into a SAS data set, but I'm talking about before I've even imported it.

Thanks very much for replying.

Super User
Posts: 19,877

Re: Import Password Protected Text Files

I think you can.

1. can you use x commands at your site?

2. Are you using Windows SAS or SAS on a Server?

3. What zipped the file, 7Zip or WinZIP?

Super Contributor
Posts: 644

Re: Import Password Protected Text Files

Have you considered placing the unzipped text files in a folder/directory to which you have exclusive read/write access?  I have seen this used successfully in several sites.  The advantage is that you can read and analyse the data without any password requirement, but other users cannot access the data even if they use your code.  Once the data has been read it can be zipped and password protected for archive, for additional security.  The same folder can be the library holding record level datasets, if required.

Super Contributor
Posts: 474

Re: Import Password Protected Text Files

Hi.

If those files are "restorable" with a system command then there should be no problem to import them through a pipped command line.

You just have to adjust your previous file assignment to a proper file pipe command assignment. Now, important thing is, beside providing the necessary password you need to add the flag which redirects processing to screen/console (in order to pipe the result). You'll have to find this flag in the zip command documentation you're using.

On Unix using the zip command, it should look like this (-c is the flag which redirects output to screen):

* flags: -c output to stdout, -q quiet mode, -P specify the password;

filename myfile pipe 'unzip -cq –P mypass FILE.zip' ;

data _null_;

     infile myfile; * import file;

     input;

     put _infile_;

run;

Cheers from Portugal.

Daniel Santos @ www.cgd.pt

Regular Contributor
Posts: 164

Re: Import Password Protected Text Files

Posted in reply to DanielSantos

Thank you all for such detailed answers!

As for what I have "on-site", I am an off-site consultant and keep the data on my drive.  I have encrypted files, security software etc. but want to take extra steps to ensure that the data is not compromised via hacking or anything so being able to extract from a zipped file makes the most sense.

I'll review all responses in more detail and may have more questions....thanks again to all of you.  I love this site!!

Regular Contributor
Posts: 164

Re: Import Password Protected Text Files

Posted in reply to DanielSantos

Hi Daniel

I'm still working on this and though I posted about SASZIPAM earlier today, I would still like to review your PIPE method.

You provided me with the code using the Unix zip command but can you advise where I can find out about the Windows (7) one?   Thanks.

Trusted Advisor
Posts: 2,116

Re: Import Password Protected Text Files

Shellp55,

To use the x command to unzip files on the PC requires a special (a.k.a. extra cost) add-on for WinZip.  However, 7Zip includes that tool in its distribution (and 7zip can process WinZip encrypted files).  Of course, this adds the extra layer of protecting the password in your SAS code.

Doc Muhlbaier

Duke

Regular Contributor
Posts: 164

Re: Import Password Protected Text Files

Hi Doc

Thanks for your reply.  Right now each single file is in a winzip folder and I'm going to be combining them into one so I will look at 7Zip.

Regular Contributor
Posts: 164

Re: Import Password Protected Text Files

Hi

I don't know what the issue is but I can't get this to work either.

This is the error log:

1    filename test Pipe '7za e "F:\files\Test.7z"
2    "myfile.txt" -y -so';
3
4    data import_test;
5    infile test;
6
7    input @1    Prov            $1.
8          @2    Inst            $4.
9          @6    Fyear           $4.
10         @10   Period          $2.
11         @12   Batch           $2.
12         @14   AbsNo           $3.
13         @18   Coder           $2.
14         @20   ChartNo         $10.
15         @30   RegNo           $7.
16         @37   SecChartNo      $10.
17         @47   MatNBChart      $10.
18         @57   HCN             $12.
19         @69   Postal          $6.
20         @75   Rescode         $7.
21         @82   Sex             $1.
22         @83   ProvHCN         $2.
23         @85   RFP             $2.;
24
25   run;

NOTE: The infile TEST is:
      Unnamed Pipe Access Device,

      PROCESS=7za e "F:\files\Test.7z""myfile.txt"
      -y -so,
      RECFM=V,LRECL=256

Stderr output:
'7za' is not recognized as an internal or external command,
operable program or batch file.
NOTE: 0 records were read from the infile TEST.
NOTE: The data set WORK.IMPORT_TEST has 0 observations and 17 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds

Is there something wrong with my code and if not, what should I be troubleshooting?  Thanks.

Regular Contributor
Posts: 164

Re: Import Password Protected Text Files

Hi

Just an FYI that the software to use the x command for WinZip is a free download so I tried that.  Based on the information, including the syntax to do so, I ran the program below but it isn't extracting from the text file portion.  The log doesn't indicate any errors, just that "0 records were read from the infile testing".

Can someone please advise why this isn't working?   Any and all assistance greatly appreciated.

filename testing pipe '"C:\Program Files\WinZip\wzunzip.exe" -vb F:\myfolder\Test.zip test.txt';


data work.import_test;
infile testing truncover LRECL = 5000 firstobs=10;


input @1 Prov   $1.
   @2 Inst   $4.
   @6 Fyear   $4.
   @10 Period   $2.
   @12 Batch   $2.
   @14 AbsNo      $3.
   @18  Coder   $2.
   @20 ChartNo   $10.
   @30 RegNo   $7.
   @37 SecChartNo  $10.
   @47 MatNBChart  $10.
   @57 HCN   $12.
   @69 Postal   $6.
   @75 Rescode   $7.
   @82 Sex   $1.
   @83 ProvHCN   $2.
   @85 RFP   $2.;
run;

Contributor
Posts: 29

Re: Import Password Protected Text Files

Hi,

1.you can directly read compressed data without extracting them first using SASZIPAM. 

Please refer the following sugi for the detailed usage.

http://www2.sas.com/proceedings/sugi31/155-31.pdf

2. Now too your question, whether we can read a password protected zip file. 

Yes,This is also possible if the unzip/ uncompress software that you use in your environment allows this.  In unix environment pkzip software allows this. I hope similarly winzip can do the same in windows environment.

Valued Guide
Posts: 634

Re: Import Password Protected Text Files

@Jonam,

Although I have not had it fail, I just recently learned that the SASZIPAM fileref engine is not recommended for use by SAS.

http://support.sas.com/kb/31/244.html

Ask a Question
Discussion stats
  • 13 replies
  • 1839 views
  • 6 likes
  • 7 in conversation