BookmarkSubscribeRSS Feed
ebphd
Calcite | Level 5

I have a sas and a sas7dbat file from a DHS database. I have successfully uploaded to myfolders, and can open the sas7dbat as well as the sas file dataset, but unable to create the libname so that I can work with the data. Below is my code. The first line came with the data and is the origin of the raw data from DHS. the sas7dbat has the variables with columns. I am using the latest SAS University edition.

 

libname user 'C:\COUNTRIES\PH70';
RUN;

libname PHFW71FL "c:/folders/myfolders/";
data PHFW71FL;
infile "/folders/myfolders/PHFW71FL.SAS7BDAT";
PROC PRINT data = PHFW71FL;
RUN;

 

15 REPLIES 15
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am guessing from the code you posted that you are using SAS University Edition?  If so you need to point your libname to the folders area, per the instructions and video training you get when you get the software.  C: does not exist in terms of SAS UE which is all on a virtual image.  I would highly recommend you go through the videos and training materials which will cover all of why your code is wrong in several places, but some tips:

libname user 'C:\COUNTRIES\PH70';    <- needs to point to /folders/myfolders (acutally, remove, as dup of other libname)
RUN;     <- is not needed, remove.

libname PHFW71FL "c:/folders/myfolders/";    <- needs to point to /folders/myfolders
data PHFW71FL;
infile "/folders/myfolders/PHFW71FL.SAS7BDAT";  <- you do not infile datasets, you simply set <libaname>.<dataset>; 
<-  Missing run;, good programming practice = always finish blocks
PROC PRINT data = PHFW71FL;  <- not needed, remove.
RUN;

Also, avoid coding in upperase, it makes code harder to read.  Your final code will look something like (and note this does nothing but create a duplicate dataset from your input):

libname phfw71fl "/folders/myfolders";

data want;
  set phfw71fl.phfw71fl;
run;
ebphd
Calcite | Level 5
Thanks. I will try this. I just need to start working with the variables.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

To start working with a tool, you need to know how to use the tool.  Learning the basics before jumping in will get you going faster, than trying to work it all out as you go along.

ebphd
Calcite | Level 5

Yes, thanks.

I have a basic understanding of sas, but now working with a dataset that I need to clean up (class project). the sas file does not have the columns, but the sas7bdat does have the columns. I want to work off of the sas7dbat.

 

I used the code provided and here is the log after I ran the code

 

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 libname phfw7lfl "/folders/myfolders";
NOTE: Libref PHFW7LFL was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders"
74 data want;
75 set phfw71fl.phfw71fl;
ERROR: Libref PHFW71FL is not assigned.
76 run;
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 0 variables.
 
Can I access the uploaded sas7bdat file? Here is the code that came with the table:
 
PROC SQL;
CREATE TABLE WORK.query AS
SELECT FW101 , FW000 , FW102 , FW103 , FW104 , FW105 , FW106 , FW107 , FW108 , FW109 , FW110 , FW111 , FW112 , FW113A , FW113B , FW113C , FW113D , FW113E , FW113F , FW113G , FW113H , FW113I , FW113J , FW113K , FW113L , FW113M , FW113X , FW113Y , FW114 , FW115 FROM _TEMP0.PHFW71FL;
RUN;
QUIT;

PROC DATASETS NOLIST NODETAILS;
CONTENTS DATA=WORK.query OUT=WORK.details;
RUN;

PROC PRINT DATA=WORK.details;
RUN;
Amir
PROC Star

Hi,

 

The libname was successfully assigned as PHFW7LFL, but your set statement refers to libref PHFW71FL (used a "1" instead of "L" in the middle). Theses two librefs need to be the same so perhaps copy and paste one to the other.

 

 

Regards,

Amir.

ebphd
Calcite | Level 5

Yes, I did that, but I also need to work with the sas7bdat file, as these have the columns. The sas file that was sent just has the raw data. How can I transfer that sas7bdat file so that I can work with the data? The code for the table is below:

 

PROC SQL;
CREATE TABLE WORK.query AS
SELECT FW101 , FW000 , FW102 , FW103 , FW104 , FW105 , FW106 , FW107 , FW108 , FW109 , FW110 , FW111 , FW112 , FW113A , FW113B , FW113C , FW113D , FW113E , FW113F , FW113G , FW113H , FW113I , FW113J , FW113K , FW113L , FW113M , FW113X , FW113Y , FW114 , FW115 FROM _TEMP0.PHFW71FL;
RUN;
QUIT;

PROC DATASETS NOLIST NODETAILS;
CONTENTS DATA=WORK.query OUT=WORK.details;
RUN;

PROC PRINT DATA=WORK.details;
RUN;

 

The datafile name is PHWF71FL.SAS71bdat. Do I need to export to an excel or csv and then import again, as I downloaded from the DHS website with these file names?

 

 

ebphd
Calcite | Level 5

Yes, I did that, but I also need to work with the sas7bdat file, as these have the columns. The sas file that was sent just has the raw data. How can I transfer that sas7bdat file so that I can work with the data? The code for the table is below:

 

PROC SQL;
CREATE TABLE WORK.query AS
SELECT FW101 , FW000 , FW102 , FW103 , FW104 , FW105 , FW106 , FW107 , FW108 , FW109 , FW110 , FW111 , FW112 , FW113A , FW113B , FW113C , FW113D , FW113E , FW113F , FW113G , FW113H , FW113I , FW113J , FW113K , FW113L , FW113M , FW113X , FW113Y , FW114 , FW115 FROM _TEMP0.PHFW71FL;
RUN;
QUIT;

PROC DATASETS NOLIST NODETAILS;
CONTENTS DATA=WORK.query OUT=WORK.details;
RUN;

PROC PRINT DATA=WORK.details;
RUN;

 

The data file name is PHWF71FL.SAS71bdat. Do I need to export to an excel or csv and then import again, as I downloaded from the DHS website with these file names?

 

 

Tom
Super User Tom
Super User

If the filename is really in all uppercase letters then you will not be able to read using SAS on unix.

You will need to rename to file to use all lowercase letters.

Otherwise SAS will not be able to see the file.

ebphd
Calcite | Level 5

I have been using uppercase for other codes. I have the university edition.

Tom
Super User Tom
Super User

@ebphd wrote:

I have been using uppercase for other codes. I have the university edition.


It doesn't matter what case you use in the CODE.  But the name of the physical file on the unix disk needs be in all lowercase letters.

If the file you downloaded had been made (or used) on a PC then it might have some uppercase letters in its name. On unix that file will be basically invisible to SAS.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would once again point you to my original post above.  This is the most basics of tasks in this software, if you cannot do this, then you will not be able to do anything else in the system.

libname mylibref "/folders/myfolders";

data want;
  set mylibref.phfw71fl;
run;

You will see that I create a reference to mylibref (I changed it so its clear) as a path on the virtual machine.  This is your library reference and once assigned you will see any files in that area in the library viewer.  I can refer to files within that area using the reference mylibref followed by a dot, then the dataset name.  

Uppercase should be lower case as @Tom.  In fact it is important to remember that case does have meaning in various aspects, in this case for the operating system, in case of upper case code its the person reading it.  Now the code you posted (and note how I use the code window which is the {i} above post area) should be changed to use your librefence:

proc sql;
  create table query as
  select FW101 , FW000 , FW102 , FW103 , FW104 , FW105 , FW106 , FW107 , FW108 , FW109 , FW110 , FW111 ,
FW112 , FW113A , FW113B , FW113C , FW113D , FW113E , FW113F , FW113G , FW113H , FW113I ,
FW113J , FW113K , FW113L , FW113M , FW113X , FW113Y , FW114 , FW115 from mylibref.phfw71fl; quit;

Will create a table called query in the SAS created temporary work library.

 

Seriously though, if your going to do anything with SAS then go through the videos which explain all this in detail, read the help and documentation.  Otherwise your not going to get anywhere.

 

 

ebphd
Calcite | Level 5

Thanks. This particular file did not respond to any of the suggestions for a lib name. (I had a statistician work on it too, but did not capture all the data). I am working off the code that came with the sas7bdat file, through the work.query pathway. 

 

ebphd 

Tom
Super User Tom
Super User

@ebphd wrote:

Thanks. This particular file did not respond to any of the suggestions for a lib name. (I had a statistician work on it too, but did not capture all the data). I am working off the code that came with the sas7bdat file, through the work.query pathway. 

 

ebphd 


What is it that you want to do.

 

How are you running SAS?  Are you using SAS/Studio?  Enterprise Guide?  SAS Display Manager?  Something else?

Did you download the SAS university edition? If so then you are using SAS/Studio and the actual SAS process is running in a unix virtual machine.

 

What files do you actually have?   What are their names?  What do they contain? Where have you placed them on your machine? Under what path can SAS see them?

 

A SAS dataset will be in a file with sas7bdat extension. 

A SAS program should be in a file with sas extension, but since it is just text the extension does not matter. 

The raw data would normally be in a file with txt, dat, csv extension. If you have raw data then you need a SAS program to read it into a SAS dataset.  Or you might have the data in some other format, like an Excel spreadsheet which would have either an XLSX or XLS extension.

ebphd
Calcite | Level 5
SAS University Edition. SAS7BDat file from. DHS site, a SAS7bdat table. I am working off the table and can code from here. Though it has a lib pathway once uploaded, the columns do not show up unless I work off the work.query pathway. I am ok with this as long as I can work with the data.

Thanks.
ebphd

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • 1828 views
  • 0 likes
  • 4 in conversation