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

I try to use proc print to make a table of the data and it runs and produces the table but it give the error that work.p2_data does not exist.

 

I have imported the data with lib name and am getting the error "Table needs to have at least one column.  I imported the sas7bat file and it ran without any errors.

LIBNAME p2 "/home/u59418563/sasuser.v94/";
DATA p2_data;
SET "/home/u59418563/sasuser.v94/p2.sas7bdat";
RUN; 
 
/*Five other explanatory variables: ALC_DAY AGEGROUP MARITAL HLTHPLN1 MEDCOST*/
 
 
PROC PRINT;
VAR  ADDEPEV3 SLEPTIM1 ALC_DAY AGEGROUP MARITAL HLTHPLN1 MEDCOST;
DATA p2_data;
RUN;
 
PROC SQL outobs=10;
create table work.p2_data as
select * from work.p2_data;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

These two lines are what is making your empty dataset.

DATA p2_data;
RUN;

You ran a dataset step that neither read in any dataset or raw data or generated any data.  You never even defined any variables.

 

The rest of the code is pretty confused also.

The first statement defines a libref of P2 that is never used.  Not only do you never use it it is pointing to the same folder that SASUSER should already be pointing to.  So you could have just use the SASUSER libref that already exists instead of running a libname statement.

 

The next three lines will copy the SASUSER.P2 dataset into the WORK.P2_DATA dataset.

Your next two active statements  will print some of the vairables and all of the observations from that dataset. Since you did not tell PROC PRINT what dataset to use it will use the most recently created dataset.

 

Then your next two lines replace you WORK.P2_DATA dataset.

 

Then you PROC SQL code tries to replace the WORK.P2_DATA datsaet with itself again.

 

If you want to print 10 observations just use the OBS= dataset option.

proc print data=sasuser.p2 (obs=10);
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

These two lines are what is making your empty dataset.

DATA p2_data;
RUN;

You ran a dataset step that neither read in any dataset or raw data or generated any data.  You never even defined any variables.

 

The rest of the code is pretty confused also.

The first statement defines a libref of P2 that is never used.  Not only do you never use it it is pointing to the same folder that SASUSER should already be pointing to.  So you could have just use the SASUSER libref that already exists instead of running a libname statement.

 

The next three lines will copy the SASUSER.P2 dataset into the WORK.P2_DATA dataset.

Your next two active statements  will print some of the vairables and all of the observations from that dataset. Since you did not tell PROC PRINT what dataset to use it will use the most recently created dataset.

 

Then your next two lines replace you WORK.P2_DATA dataset.

 

Then you PROC SQL code tries to replace the WORK.P2_DATA datsaet with itself again.

 

If you want to print 10 observations just use the OBS= dataset option.

proc print data=sasuser.p2 (obs=10);
run;
Reeza
Super User
LIBNAME myData "/home/u59418563/sasuser.v94/";
DATA p2_data;
SET myData.p2;
RUN; 
 
/*Five other explanatory variables: ALC_DAY AGEGROUP MARITAL HLTHPLN1 MEDCOST*/
 
*Add DATA= and explicitly list the data set to print;
PROC PRINT DATA=p2_data;
VAR  ADDEPEV3 SLEPTIM1 ALC_DAY AGEGROUP MARITAL HLTHPLN1 MEDCOST;

*This replaces your data, you should create a new data set with the 10 observations;
PROC SQL outobs=10;
create table work.p2_data2 as
select * from work.p2_data;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 19201 views
  • 1 like
  • 3 in conversation