BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amithabh
Calcite | Level 5

I have the datasets needed for working with the SAS Base Certification prep guide(libname sasuser "/folders/myfolders/certprep";). Now, I would like to use a SAS dataset in the certprep folder to create a raw dataset and store it in the same folder. The prep guide book only explains on how to store it locally in your computer for which there are authorization issues.For storing locally in my computer, the following code exists:

libname sasuser "/folders/myfolders/certprep";

data _null_;

   set sasuser.acities;

    file 'C:\clinic\patients\acities.dat'

run;  

How can I modify the above code to store the output raw data within the SAS environment?

Thanks in advance.

Amithabh

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  The interface you use to SAS is just that -- an interface. The interface is NOT SAS -- the interface is just how you get to SAS to run a program. I have used many, many different interfaces over my career with SAS and I can tell you that if you get hung up now on only using SAS on Windows versus using SAS Studio (to access SAS on Unix), you are limiting yourself. Trust me when I say that using SAS Studio is enormously, enormously, better than using VI to type SAS code.
     

  You CAN write to your C: drive. I have proved that you can write to your C: drive. For example, my C: drive has these physical folders:

c:\SASUniversityEdition\myfolders/certprep and this folder c:\SASUniversityEdition\myfolders\wombat and c:\SASUniversityEdition\myfolders\ecprg193 -- those are 3 physical folders on MY local C: drive. However, notice that the high level part of the path name is: c:\SASUniversityEdition\myfolders that's because that is the physical location I defined to my virtualization software to use as a "shared folder" location. So when my SAS Studio talks to SAS University Edition, using VMWarePlayer or Virtual Box, my SAS Studio cannot use the C: drive reference. It has to use the Unix "alias" for the C: drive shared folder location. That breaks down this way:

C drive shared folder name                                                             equates to

c:\SASUniversityEdition\myfolders\certprep   /folders/myfolders/certprep

c:\SASUniversityEdition\myfolders\wombat     /folders/myfolders/wombat

c:\SASUniversityEdition\myfolders\ecprg193   /folders/myfolders/ecprg193

So, when you write to:

file '/folders/myfolders/certprep';

in a program on SAS University Edition, SAS uses the Unix name. Then it asks your Virtualization software (VMware player or Virtual Box) to put that file into the right C: drive location. For example, when you go to send your Mom a birthday present, you say to yourself, I'm going to send this to Mom. But UPS or the Post Office will not take a package labeled "To: My Mom", you have to use a special address on the package. You have to put down your Mom's full name and her street address and city on the package before UPS or the Post Office can deliver the package. Just think of the /folders/myfolders location as the kind of name you need to use to get SAS to read or write files from your C:\ drive. And, if your shared folder was defined as:

c:\users\xxxyyy\MySASFiles\SASUniversityEdition\myfolders\certprep  the Unix name is still: /folders/myfolders/certprep

  You can go to your shared folder location on the Windows side, using Windows Explorer and FIND the files that you wrote using that Unix name -- look at my screen shot showing Windows Explorer and my newclass.txt and newclass.csv files created above. In fact, all the code in Programming 1 will work the same no matter what operating system and version of SAS you use. The ONLY, ONLY thing that changes are some of the options that are operating system specific and the way you use path names to read and write your files and point to your SAS libraries. For example, you cannot guarantee that you will ALWAYS have a job using SAS on Windows. In fact, I think that is probably the least likely usage scenario these days. Here is a libname statement for different operating systems:

SAS on Windows with mapped drive: libname orion 's:\workshop';

SAS on Windows C location: libname orion 'c:\SAS_Education\ecprg193';

SAS on Unix: libname orion '/usr/bin/data/ecprg193';

SAS on Mainframe: libname orion 'SASCZZ.USER.SASDATA.ECPRG193' disp=shr;

And, no matter which of the LIBNAME statements I use, this program:

proc print data=orion.customers(obs=5);

run;

proc freq data=orion.customers;

  tables Customer_Country;

run;

would work an ANY operating system, as long as my LIBNAME statement was correct for that system. So, what we wanted you to pay attention to in Programming 1 was the code, not the interface to SAS. And the new Programming 1 has a couple of demos explicitly that show using SAS Studio, using SAS Enterprise Guide and using SAS on Windows.  Did we do EVERY demo in each possible interface? No -- and there's no need to. It is the code that is important, not the interface. The bottom line is that you CAN write to and read from your C: drive using SAS University Edition.

cynthia


show_c_drive_for_created_raw_files.png

View solution in original post

16 REPLIES 16
ballardw
Super User

I think you may need to define what you are looking for by "raw data". Do you mean a flat text file or another SAS dataset?

If you are looking to build a text file then proc export may be the simplest.

amithabh
Calcite | Level 5

ballardw wrote:

I think you may need to define what you are looking for by "raw data". Do you mean a flat text file or another SAS dataset?

If you are looking to build a text file then proc export may be the simplest.

I tried exporting but get an error:

proc export data=sashelp.class

  outfile='c:\myfiles\class'

  dbms=dlm;

  delimiter='&';

run;

ERROR: Insufficient authorization to access /opt/sasinside/SASConfig/Lev1/SASApp/c:\myfiles\class.

ballardw
Super User

The SASUSER library should already exist in a SAS install, so I wouldn't try re-assigning it.

You can find the actual path to the sasuser library using:

Data _null_;

     length path $ 200;

     path= pathname(SASUSER,L);

     put path=;

run;

put the value of the path in place of c:\myfiles in outfile='c:\myfiles\class'. I would recommend putting an extension on the file CLASS such as .txt.

amithabh
Calcite | Level 5

ballardw wrote:

The SASUSER library should already exist in a SAS install, so I wouldn't try re-assigning it.

You can find the actual path to the sasuser library using:

Data _null_;

     length path $ 200;

     path= pathname(SASUSER,L);

     put path=;

run;

put the value of the path in place of c:\myfiles in outfile='c:\myfiles\class'. I would recommend putting an extension on the file CLASS such as .txt.

I tried to find the path using your code but the log message had path = blank but managed to find it directly from the properties of the sasuser library. Now that I have the dataset in the sasuser library, how can I see the contents of the newly created mydata.csv file without directly going to the library. I tried doing,

proc print data=sasuser.mydata;

run;

but get an error:

ERROR: File SASUSER.MYDATA.DATA does not exist.

Reeza
Super User

You save a dataset by using LIBNAME.DATANAME where libname is the location of where you want to save the file and DATANAME is the name of the dataset.

An example based on your sasuser library is here:

data sasuser.class;

set sashelp.class;

run;

amithabh
Calcite | Level 5

Reeza wrote:

You save a dataset by using LIBNAME.DATANAME where libname is the location of where you want to save the file and DATANAME is the name of the dataset.

An example based on your sasuser library is here:

data sasuser.class;

set sashelp.class;

run;

But the above procedure creates another SAS dataset in the sasuser library, right? But I would like to create a raw data file(like a .csv file).

Cynthia_sas
SAS Super FREQ

Hi:

  With SAS University Edition, you do not have access to the SASUSER library. If you are using the changed programs for the Prep Guide, for the University Edition, then the way you create a "raw" data file is done with either ODS or with a DATA step program. For example, here's a DATA step program that writes out a "raw" data file from a SAS dataset. In the code below, instead of writing to the "certprep" location, I wrote to a different folder under my shared folder location. Please note the code below:

** make a file delimited by !;
data _null_;
  set sashelp.class;
  file '/folders/myfolders/all_output/newclass.txt' termstr=CRLF;
  if _n_ = 1 then do;
    put "Name!Age!Sex!Height!Weight" ;
  end;
  if age GE 14 then do;
    put name '!' age '!' sex '!' height '!' weight  ;
  end;
run;

** use ODS to make a file delimited by commas;
ods csv file='/folders/myfolders/all_output/newclass.csv' rs=none;
  proc print data=sashelp.class;
  where age ge 14;
  run;
ods csv close;

If you decide that you want to write to your "certprep" folder, then you would need to change only 2 statements:

file '/folders/myfolders/certprep/aaa_newclass.txt' termstr=CRLF; in the first program and ods csv file='/folders/myfolders/certprep/aaa_newclass.csv' rs=none; in the second program (assuming that your "certprep" directory is in your shared folder location defined by /folders/myfolders/certprep. For purposes of studying with the Prep Guide in the University Edition, if you are using the altered programs (as the use of the "certprep" folder implies, then for SAS dataset, the "certprep" folder is being used as the location of SASUSER inside the University Edition. You were instructed to always run this LIBNAME statement before running any of the programs in the Prep Guide:

libname sasuser '/folders/myfolders/certprep';

This is so you could run a job like this:

data sasuser.class;

      set sashelp.class;

  run;

and then you would NOT get WRITE access violations in the University Edition.

However, you cannot use a LIBNAME to write out "flat" files or "raw" files, you have to use a FILENAME or FILE statement and for ODS, a FILE= option. So instead of thinking that you are writing to SASUSER, (which has been redirected to the "certprep" folder, think of it as that you want to write to the physical file location that SAS treats as SASUSER. Then, needing to use the /folders/myfolders/certprep path in the FILENAME statement or the FILE statement or the FILE= option seems to make more sense (to me). Please see the log and the output files in the attached screen shots. They show writing to the all_output shared folder, but you could just as easily have written to certprep, as shown in the 3rd screen shot.

cynthia

  Note about the code. Normally, you don't need the TERMSTR option or the RS= option in your code. But since SAS UE is a Unix machine and you are probably wanting to view the files with Notepad on Windows (or a text editor on Windows), you must get the "right" carriage return (CR)/ line feed (LF) characters inserted into the raw data file when it's created by SAS on Unix. the TERMSTR option does that for the FILE statement and the RS= option does that for the ODS CSV file.


use_ods_UE.pnguse_CSV_UE_other_folder.pnguse_datastep_UE.png
amithabh
Calcite | Level 5

Thanks a lot Cynthia. I have a few more questions:

1) I tried to open the file in a proc print step but in vain. Is it possible to view the newclass.txt using a proc print step? How to access the data in the certprep folder in general?

2) What about the write privileges to work and sashelp library in University Ed.?Is it the same as sasuser library?

3) I see that there is an option to create a new library. Is it possible to create one with write previleges?

Reeza
Super User

1) Procs are meant to interact with SAS data sets not raw text files. You should import a file into a SAS data set and then work with it.

2) You can write to WORK. I'd avoid writing to SASHELP even if you can as some of the data sets in there are metadata related and used in examples throughout tutorials.

3) Yes - There is a list of FAQ's and a course teaching you how to use SAS freely available on the SAS UE page. I highly recommend you take the courses.

Cynthia_sas
SAS Super FREQ

Hi:
     

1) you can only use a SAS dataset with PROC PRINT (or a data source, like a database file that SAS treats as a SAS dataset), so if you create a simple ASCII text file, from SAS, the assumption is that you do NOT want to use SAS to view the file. The assumption is that you will use a text editor like NOTEPAD to view the file. So it is not appropriate to use PROC PRINT to view the newclass.txt file, such as I showed in my previous posting screen shot. That's why I showed the file in Notepad. There are some products that you can use inside some installations of SAS to view "flat" or "raw" files (like PROC FSLIST), but SAS University Edition does not come with PROC FSLIST. Your original question was how to create a "raw" data file. In our Programming 1 class, we teach about the difference between a "raw" data file and a SAS dataset. Usually you read "raw" datafiles into SAS format because you want to analyze or report on the data using SAS. Usually you write "raw" data files from a SAS dataset because you are passing the SAS data to an application that does not read SAS proprietary format - so you must create a file that your other application can read. For example, assume that you have SAS and your boss has Quattro Pro and you have a SAS dataset and your boss wants to work with the data in Quattro -- then you might make a CSV file FROM your SAS dataset so that your boss could load the CSV file into Quattro. There would be no reason for you to use PROC PRINT on the CSV file, because a CSV file is NOT a SAS dataset. On the other hand, if your boss has some data of his own in Quattro and then he says to you, "Hey, I have this Quattro data, could you just print it up for me with fancy titles and some footnotes?" You could have your boss make a CSV file from Quattro and then you would READ the CSV file into SAS format so you could use PROC PRINT on the data.

  To access the "raw" data files in the certprep directory (or any directory), you must use an INFILE statement or a FILENAME statement (although the INFILE method is the one we show most in PROGRAMMING1). For example, in the certprep folder, there is a file called BOOKDATA.DAT, this is a "raw" data file that contains a book code, a type indicator and a numeric variable for number sold. If you want to read that data file into SAS format, then you would need a DATA step program, as shown in the attached PDF file. In fact, there are 3 different ways to read the same data file and the PDF file shows you the successful log from all 3 ways. I am only posting the INFILE method (Method 1) here:

** Method 1: use a fully qualified path in the INFILE statement;
data book1;
  infile '/folders/myfolders/certprep/bookdata.dat';
  input booknum $ type $ numsold;
run;

   

proc print data=work.book1;
  title 'Create dataset using method 1';
run;

The INFILE statement uses a fully qualified path, as identified by the SAS University Edition shared folder name of /folders/myfolders and subdirectory name of "certprep", with the full name of the file, including the file extension .

2) You can of course write to the WORK library, no matter what your operating system is (unless your administrators have restricted this access). The WORK library is automatically allocated when you first start up your SAS session and the location of your WORK library is generally determined by the people who install/configure SAS. For the SAS UE, the WORK library will be some location like this

/tmp/SAS_work928200004B25_localhost.localdomain/SAS_work805800004B25_localhost.localdomain which should be a write-able location whose location is set by SAS University Edition (but remember that the WORK library is transient and goes away when the session ends). The screen shot write_WORK_UE.png shows writing to the WORK location and the Properties window in that screen shot also shows the location of my WORK library. Your location, will of course, be different.

  As you can see from my screen shot, it is possible to write a SAS dataset to WORK and then run PROC PRINT on the created dataset. So you automatically have WRITE privileges to the WORK library. However, the SASHELP library is a proprietary library. It is part of SAS and you do not generally have write access to it and in the University Edition, you absolutely do not have write access to the SASHELP library. For example, see these screen shots: sashelp_inside_UE.png and UE_cannot_write_SASHELP.png So, you only have READ access to the SASHELP library when you use the SAS University Edition.

  So, the bottom line on read/write access is:

a) WORK you have WRITE access

b) SASHELP you have READ access

c) SASUSER -- initially with the SAS University Edition, you do NOT have WRITE access; but you can redirect SASUSER to a location where you do have WRITE access. This was explained in the instructions for making the Prep Guide data for use in the University Edition. Specifically, it says:

--begin quote

   When the Prep Guides were originally written, the SAS
University Edition and SAS Studio did not exist, so the original instructions
had students run a program that wrote the course data to the SASUSER library.

    In many usage scenarios, this works just great. However, in the SAS University Edition,
the SASUSER library is on your virtual machine and the program you run does not
have write access to this location on the virtual machine

  However, it is possible to “redirect” your SASUSER library to a location in the SAS
Studio interface to the University Edition, where you do have write access (such as your shared folder).

--end quote

  But, the ONLY library that needs any special accommodation for studying with the Certification Prep Guide is the SASUSER library, and ONLY for file creation. In the Prep Guide itself, you will see them assign different LIBNAME statements that point to the same location as SASUSER. For example, in the section on reading data (Chapter 5, page 146 in the 2nd Edition), there is a program that reads the EXER.DAT file. I have attached an annotated copy of that page. Even if you have a different edition, you should be able to find this example in the book. Note that the ONLY difference between the code shown in the book and the code that worked in the University Edition is that I changed the FILENAME statement, you can see the successful log in the screen shot log_UE_create_read_exercise_data.png.
     

3) As long as you correctly specify your SASUniversityEdition/myfolders shared folder or to a location under that folder in your LIBNAME statement, that is the easiest way to define a new library. But do remember, the physical folder MUST exist before you point to it with the LIBNAME statement. So if you do this:

libname newlib '/folders/myfolders/wombat';
     

and there is no physical structure: c:\SASUniversityEdition\myfolders\wombat, then you will receive this NOTE:

NOTE: Library NEWLIB does not exist.

and if you continue to use the bad reference, later you will receive an error message:

ERROR: Library NEWLIB does not exist.      

But if the wombat folder does exist in the shared location on the C: drive, then you should be able to do this:

libname newlib '/folders/myfolders/wombat';

 

data newlib.cars;

  set sashelp.cars(obs=5);

run;

 

proc print data=newlib.cars;

run;
      

As shown in my "successful" screen shot, successful_new_lib_when_folder_exists.png. My recommendation is that if you do write to the redirected SASUSER library then adopt a naming convention so you don't accidentally overwrite one of the files that was provided for your study purposes. For example, you could precede every name with your initials or you could precede every name with XX_ such as:

data sasuser.A_exercise; or

data sasuser.XX_exercise;

  My other recommendation is that the Prep Guide was designed as a preparation for students who had already taken Programming 1 and Programming 2 and who were preparing for the certification exam, as a way of getting extra practice. The Prep Guide is not intended to replace taking those classes. Have you taken Programming 1? Even if you can't take Programming 2, the Programming 1 e-learning class is free and I would recommend that you work through that class first, before you start working with the Prep Guide. The Prep Guide assumes that you have the basic knowledge and experience that you would gain by taking Programming 1 and Programming 2. So, jumping into the Prep Guide could be confusing if you have NEVER used SAS before.
    

Cynthia 


UE_cannot_write_SASHELP.pngsuccessful_new_lib_when_folder_exists.pngtypical_error_no_physical_folder.pngwrite_WORK_UE.pnglog_UE_create_read_exercise_data.pngsashelp_inside_UE.png
amithabh
Calcite | Level 5

Hi Cynthia,

   I really appreciate your time and effort. It was very helpful. I have taken the programming 1 course but it explains everything using SAS windowing environment and so I was not sure what part of it is applicable to the UE. My intention to access a raw dataset in SAS is just to have a little bit of flexibility and to know if it is really possible though not necessary. Moreover, though I can use the prep guide with the data already created by the method suggested, it would be nice to be able to access the data in the C drive. I feel that this constraint in UE is really a handicap. Is there a SAS client application which doesn't have any such limitations?

Amithabh

Cynthia_sas
SAS Super FREQ

Hi:

  The interface you use to SAS is just that -- an interface. The interface is NOT SAS -- the interface is just how you get to SAS to run a program. I have used many, many different interfaces over my career with SAS and I can tell you that if you get hung up now on only using SAS on Windows versus using SAS Studio (to access SAS on Unix), you are limiting yourself. Trust me when I say that using SAS Studio is enormously, enormously, better than using VI to type SAS code.
     

  You CAN write to your C: drive. I have proved that you can write to your C: drive. For example, my C: drive has these physical folders:

c:\SASUniversityEdition\myfolders/certprep and this folder c:\SASUniversityEdition\myfolders\wombat and c:\SASUniversityEdition\myfolders\ecprg193 -- those are 3 physical folders on MY local C: drive. However, notice that the high level part of the path name is: c:\SASUniversityEdition\myfolders that's because that is the physical location I defined to my virtualization software to use as a "shared folder" location. So when my SAS Studio talks to SAS University Edition, using VMWarePlayer or Virtual Box, my SAS Studio cannot use the C: drive reference. It has to use the Unix "alias" for the C: drive shared folder location. That breaks down this way:

C drive shared folder name                                                             equates to

c:\SASUniversityEdition\myfolders\certprep   /folders/myfolders/certprep

c:\SASUniversityEdition\myfolders\wombat     /folders/myfolders/wombat

c:\SASUniversityEdition\myfolders\ecprg193   /folders/myfolders/ecprg193

So, when you write to:

file '/folders/myfolders/certprep';

in a program on SAS University Edition, SAS uses the Unix name. Then it asks your Virtualization software (VMware player or Virtual Box) to put that file into the right C: drive location. For example, when you go to send your Mom a birthday present, you say to yourself, I'm going to send this to Mom. But UPS or the Post Office will not take a package labeled "To: My Mom", you have to use a special address on the package. You have to put down your Mom's full name and her street address and city on the package before UPS or the Post Office can deliver the package. Just think of the /folders/myfolders location as the kind of name you need to use to get SAS to read or write files from your C:\ drive. And, if your shared folder was defined as:

c:\users\xxxyyy\MySASFiles\SASUniversityEdition\myfolders\certprep  the Unix name is still: /folders/myfolders/certprep

  You can go to your shared folder location on the Windows side, using Windows Explorer and FIND the files that you wrote using that Unix name -- look at my screen shot showing Windows Explorer and my newclass.txt and newclass.csv files created above. In fact, all the code in Programming 1 will work the same no matter what operating system and version of SAS you use. The ONLY, ONLY thing that changes are some of the options that are operating system specific and the way you use path names to read and write your files and point to your SAS libraries. For example, you cannot guarantee that you will ALWAYS have a job using SAS on Windows. In fact, I think that is probably the least likely usage scenario these days. Here is a libname statement for different operating systems:

SAS on Windows with mapped drive: libname orion 's:\workshop';

SAS on Windows C location: libname orion 'c:\SAS_Education\ecprg193';

SAS on Unix: libname orion '/usr/bin/data/ecprg193';

SAS on Mainframe: libname orion 'SASCZZ.USER.SASDATA.ECPRG193' disp=shr;

And, no matter which of the LIBNAME statements I use, this program:

proc print data=orion.customers(obs=5);

run;

proc freq data=orion.customers;

  tables Customer_Country;

run;

would work an ANY operating system, as long as my LIBNAME statement was correct for that system. So, what we wanted you to pay attention to in Programming 1 was the code, not the interface to SAS. And the new Programming 1 has a couple of demos explicitly that show using SAS Studio, using SAS Enterprise Guide and using SAS on Windows.  Did we do EVERY demo in each possible interface? No -- and there's no need to. It is the code that is important, not the interface. The bottom line is that you CAN write to and read from your C: drive using SAS University Edition.

cynthia


show_c_drive_for_created_raw_files.png
amithabh
Calcite | Level 5

Great! The whole libname/filename statement was like a black box to me earlier. It is this mapping information that was the missing piece of information which clarifies everything. Thanks again.

JoeDerby
Calcite | Level 5

I am using SAS Studio and am having trouble reading a text file and receive the error message below. The file contains one column of data that I am separating into four columns.

I set up my_content to be my shared folder.  Although the error message says the physical file doesn't exist, the Test01.txt file is present in the my_content folder.

I also tried using the &path

I would appreciate direction on how to solve the problem

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

57 

58 %Let path=/Folders/My Folders/my_content;

59 Data DataSet00;

60 infile "/Folders/My Folders/my_content/Test01.txt";

61 Input Patent 7. Class $3. Sub $6. Type $1;

62 Put _all_;

63 run;

ERROR: Physical file does not exist, /Folders/My Folders/my_content/Test01.txt.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.DATASET00 may be incomplete. When this step was stopped there were 0 observations and 4 variables.

WARNING: Data set WORK.DATASET00 was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

  real time 0.00 seconds

  user cpu time 0.00 seconds

  system cpu time 0.00 seconds

  memory 498.03k

  OS Memory 27804.00k

  Timestamp 06/01/2015 07:47:54 PM

  Step Count 95 Switch Count 42

  Page Faults 0

  Page Reclaims 67

  Page Swaps 0

  Voluntary Context Switches 113

  Involuntary Context Switches 26

  Block Input Operations 0

  Block Output Operations 8

  

64 

65 

66 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

78 

_BLANKPAGE_

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 16 replies
  • 3882 views
  • 4 likes
  • 5 in conversation