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

Hello, I'm new and I keep getting errors when I try to create a CSV:

 

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;
PROC PRINT DATA=BASEBALL86; 
RUN;
ODS CSV CLOSE;

or exclude missings from a boxplot:

PROC SGPLOT DATA = BIRTH2001 nomiss;
 VBOX tounces / GROUP = SMOKE;
 TITLE 'Birthweights by Smoking Status';
RUN; 

Putting NOMISS in the initial PROC SGPLOT is how I think I've seen others do it, but all it does is cause a syntax error and make my graph disappear! 

Can anyone advise? Thanks!

Full code:

Spoiler
%web_drop_table(BIRTH);

FILENAME REFFILE '/home/u59281773/sasuser.v94/LIB/nc_birth.xlsx';

PROC FORMAT;
VALUE RACE /*labels the possible values of the variables*/
     0='other non-White' 1='White' 2='Black' 3='American Indian' 
     4='Chinese' 5='Japanese' 6='Hawaiian' 7='Filipino' 
     8='Other Asian or Pacific Islander';
VALUE SMOKESTAT
0 = 'No'
1 = 'Yes'  ;
      RUN; 
      
PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=BIRTH;
    GETNAMES=YES;
    SHEET='Sheet1'; /*selecting which sheet within the file to use*/
RUN;

PROC CONTENTS DATA=BIRTH; RUN;

%web_open_table(BIRTH);

data BIRTH2001;
  set BIRTH; 
  LABEL 
RACEMOM = 'Race of Mother' 
SMOKE = 'Did mother smoke during pregnancy?';
/*attempt to label the variables*/
FORMAT RACEMOM RACE. SMOKE SMOKESTAT.;
run;

*Creating the histograms;

PROC SGPLOT DATA = BIRTH2001;
 HISTOGRAM tgrams;
 TITLE 'Birthweights in Ounces';
RUN;
PROC SGPLOT DATA = BIRTH2001;
 HISTOGRAM tounces;
 TITLE 'Birthweights in Grams';
RUN; 

PROC SGPLOT DATA = BIRTH2001 nomiss;
 VBOX tounces / GROUP = SMOKE;
 TITLE 'Birthweights by Smoking Status';
RUN; 
*how to exclude missings?;


PROC SGPLOT DATA = BIRTH2001;
 REG x=gained y=tgrams;
 TITLE 'Birthweights by Weight Gain During Pregnancy';
RUN; 

DATA BASEBALL86;    
SET sashelp.BASEBALL;
TITLE 'Baseball 86 Stats';
RUN;
*create temporary dataset with preset data;

*Creating Excel file and replacing previous temp file;
PROC EXPORT DATA=BASEBALL86            
OUTFILE = '/home/u59281773/sasuser.v94/Baseball86.xlsx'            
DBMS = xlsx            
REPLACE;
RUN; 

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;
PROC PRINT DATA=BASEBALL86; 
RUN;
ODS CSV CLOSE;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

In the future, please include the errors that you're receiving or indicate what is happening. We cannot run your code as we don't have the source files.

 

For your first issue, I think you have pretty quotes around your path, it needs to be a single or double quote not the curly ones. Office applications have a tendency to add those - did you copy/paste your code from somewhere. Basically, replace your quotes around the path for the CSV file and I think it'll be fine. 

Notice how the editor doesn't color it the same way it colours other quoted text, highlighting that it's different. 

 

Regarding filtering out observations - there is no NOMISS option on SGPLOT perhaps that is in another procs you've seen? You can filter out data using a WHERE statement but it depends exactly on what you're trying to filter out. Typically missing data is filtered out by default.

 


@akimme wrote:

Hello, I'm new and I keep getting errors when I try to create a CSV:

 

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;
PROC PRINT DATA=BASEBALL86; 
RUN;
ODS CSV CLOSE;

or exclude missings from a boxplot:

PROC SGPLOT DATA = BIRTH2001 nomiss;
 VBOX tounces / GROUP = SMOKE;
 TITLE 'Birthweights by Smoking Status';
RUN; 

Putting NOMISS in the initial PROC SGPLOT is how I think I've seen others do it, but all it does is cause a syntax error and make my graph disappear! 

Can anyone advise? Thanks!

Full code:

Spoiler
%web_drop_table(BIRTH);

FILENAME REFFILE '/home/u59281773/sasuser.v94/LIB/nc_birth.xlsx';

PROC FORMAT;
VALUE RACE /*labels the possible values of the variables*/
     0='other non-White' 1='White' 2='Black' 3='American Indian' 
     4='Chinese' 5='Japanese' 6='Hawaiian' 7='Filipino' 
     8='Other Asian or Pacific Islander';
VALUE SMOKESTAT
0 = 'No'
1 = 'Yes'  ;
      RUN; 
      
PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=BIRTH;
    GETNAMES=YES;
    SHEET='Sheet1'; /*selecting which sheet within the file to use*/
RUN;

PROC CONTENTS DATA=BIRTH; RUN;

%web_open_table(BIRTH);

data BIRTH2001;
  set BIRTH; 
  LABEL 
RACEMOM = 'Race of Mother' 
SMOKE = 'Did mother smoke during pregnancy?';
/*attempt to label the variables*/
FORMAT RACEMOM RACE. SMOKE SMOKESTAT.;
run;

*Creating the histograms;

PROC SGPLOT DATA = BIRTH2001;
 HISTOGRAM tgrams;
 TITLE 'Birthweights in Ounces';
RUN;
PROC SGPLOT DATA = BIRTH2001;
 HISTOGRAM tounces;
 TITLE 'Birthweights in Grams';
RUN; 

PROC SGPLOT DATA = BIRTH2001 nomiss;
 VBOX tounces / GROUP = SMOKE;
 TITLE 'Birthweights by Smoking Status';
RUN; 
*how to exclude missings?;


PROC SGPLOT DATA = BIRTH2001;
 REG x=gained y=tgrams;
 TITLE 'Birthweights by Weight Gain During Pregnancy';
RUN; 

DATA BASEBALL86;    
SET sashelp.BASEBALL;
TITLE 'Baseball 86 Stats';
RUN;
*create temporary dataset with preset data;

*Creating Excel file and replacing previous temp file;
PROC EXPORT DATA=BASEBALL86            
OUTFILE = '/home/u59281773/sasuser.v94/Baseball86.xlsx'            
DBMS = xlsx            
REPLACE;
RUN; 

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;
PROC PRINT DATA=BASEBALL86; 
RUN;
ODS CSV CLOSE;

 

View solution in original post

4 REPLIES 4
Reeza
Super User

In the future, please include the errors that you're receiving or indicate what is happening. We cannot run your code as we don't have the source files.

 

For your first issue, I think you have pretty quotes around your path, it needs to be a single or double quote not the curly ones. Office applications have a tendency to add those - did you copy/paste your code from somewhere. Basically, replace your quotes around the path for the CSV file and I think it'll be fine. 

Notice how the editor doesn't color it the same way it colours other quoted text, highlighting that it's different. 

 

Regarding filtering out observations - there is no NOMISS option on SGPLOT perhaps that is in another procs you've seen? You can filter out data using a WHERE statement but it depends exactly on what you're trying to filter out. Typically missing data is filtered out by default.

 


@akimme wrote:

Hello, I'm new and I keep getting errors when I try to create a CSV:

 

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;
PROC PRINT DATA=BASEBALL86; 
RUN;
ODS CSV CLOSE;

or exclude missings from a boxplot:

PROC SGPLOT DATA = BIRTH2001 nomiss;
 VBOX tounces / GROUP = SMOKE;
 TITLE 'Birthweights by Smoking Status';
RUN; 

Putting NOMISS in the initial PROC SGPLOT is how I think I've seen others do it, but all it does is cause a syntax error and make my graph disappear! 

Can anyone advise? Thanks!

Full code:

Spoiler
%web_drop_table(BIRTH);

FILENAME REFFILE '/home/u59281773/sasuser.v94/LIB/nc_birth.xlsx';

PROC FORMAT;
VALUE RACE /*labels the possible values of the variables*/
     0='other non-White' 1='White' 2='Black' 3='American Indian' 
     4='Chinese' 5='Japanese' 6='Hawaiian' 7='Filipino' 
     8='Other Asian or Pacific Islander';
VALUE SMOKESTAT
0 = 'No'
1 = 'Yes'  ;
      RUN; 
      
PROC IMPORT DATAFILE=REFFILE
    DBMS=XLSX
    OUT=BIRTH;
    GETNAMES=YES;
    SHEET='Sheet1'; /*selecting which sheet within the file to use*/
RUN;

PROC CONTENTS DATA=BIRTH; RUN;

%web_open_table(BIRTH);

data BIRTH2001;
  set BIRTH; 
  LABEL 
RACEMOM = 'Race of Mother' 
SMOKE = 'Did mother smoke during pregnancy?';
/*attempt to label the variables*/
FORMAT RACEMOM RACE. SMOKE SMOKESTAT.;
run;

*Creating the histograms;

PROC SGPLOT DATA = BIRTH2001;
 HISTOGRAM tgrams;
 TITLE 'Birthweights in Ounces';
RUN;
PROC SGPLOT DATA = BIRTH2001;
 HISTOGRAM tounces;
 TITLE 'Birthweights in Grams';
RUN; 

PROC SGPLOT DATA = BIRTH2001 nomiss;
 VBOX tounces / GROUP = SMOKE;
 TITLE 'Birthweights by Smoking Status';
RUN; 
*how to exclude missings?;


PROC SGPLOT DATA = BIRTH2001;
 REG x=gained y=tgrams;
 TITLE 'Birthweights by Weight Gain During Pregnancy';
RUN; 

DATA BASEBALL86;    
SET sashelp.BASEBALL;
TITLE 'Baseball 86 Stats';
RUN;
*create temporary dataset with preset data;

*Creating Excel file and replacing previous temp file;
PROC EXPORT DATA=BASEBALL86            
OUTFILE = '/home/u59281773/sasuser.v94/Baseball86.xlsx'            
DBMS = xlsx            
REPLACE;
RUN; 

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;
PROC PRINT DATA=BASEBALL86; 
RUN;
ODS CSV CLOSE;

 

akimme
Obsidian | Level 7

I didn't realize copying and pasting from Word used different quotes! That fixed that part, thank you. Is there any other character that I can't write out in Word and copy?

 

And the WHERE statements worked!

Capture.PNG

ballardw
Super User

As @Reeza says, pretty quotes.

 

If you look closely at these two lines it is easy to see the first line uses vertical quote mark and the second curly quotes. The curly ones are not valid syntax.

OUTFILE = '/home/u59281773/sasuser.v94/Baseball86.xlsx'            

ODS CSV FILE=‘/home/u59281773/sasuser.v94/BALL1986.csv’;

What makes you think that missing values are included in a boxplot? Missing for which variable?

akimme
Obsidian | Level 7

Yep, I had the wrong quotes in there - thanks!

 

My boxplots had a third, gray box for missings. I switched NOMISS for WHERE and I think it's good to go now

 

Capture.PNGCapture2.PNG

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!
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
  • 4 replies
  • 411 views
  • 2 likes
  • 3 in conversation