BookmarkSubscribeRSS Feed
prizedeye824
Calcite | Level 5

Currently trying to import a CSV file from Excel using this code:

 

proc import datafile = "/home/u63565620/Datasets/politics.csv" out = Assignment3;
run;

 

This step usually goes fine, but I've been getting an error of:

 

PTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 
 proc import datafile = "/home/u63565620/Datasets/politics.csv" out = Assignment3;
 run;
(this is my only line of code in the program so far)
 
NOTE: Import canceled. Output dataset WORK.ASSIGNMENT3 already exists. Specify REPLACE option to overwrite it.
NOTE: The SAS System stopped processing this step because of errors.
 
The real problem is when I go to just print that data using:
 
Proc print data = politics;
Run;
 
I get this error:
 
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 Proc print data = politics;
ERROR: File WORK.POLITICS.DATA does not exist.
 Run;
 
I've already imported the file into SAS into a folder called Datasets, so I'm not sure what the issue is
 
 
9 REPLIES 9
Patrick
Opal | Level 21

Like the SAS Log tells you: Specify REPLACE option to overwrite it. Try:

proc import 
  datafile = "/home/u63565620/Datasets/politics.csv" 
  out = work.Assignment3
  dbms=csv
  replace
  ;
run;

 

I've already imported the file into SAS into a folder called Datasets, so I'm not sure what the issue is

That's the .csv file. Proc Import then reads this external text file into SAS session specific table work.assignment3 (=the table you're trying to print must exist under library WORK). WORK and all its content gets deleted when you end a SAS session.

prizedeye824
Calcite | Level 5

Thank you so much! how would I print or use a test like the chisq test after this though? I added the replace statement and now that step is working fine, but the print step still isn't working. I don't think I'm creating the data set from the imported csv correctly, but I'm not sure how to do it.

 

I'm trying to separate my data from the csv into ideological groups (the data is about political party affiliation) and this is the code I'm using 

 

PROC IMPORT FILE="/home/u63565620/Datasets/politics.csv"
OUT=WORK.politics
DBMS=CSV
replace;
RUN;

Data politics;
Set politics2;
Length opinion $15;
If ideology in (1,2) then opinion = “Liberal”;
If ideology in (3,4,5) then opinion = “Moderate”;
If ideology in (6,7) then opinion = “Conservative”;
Run;

 

but it just created extra empty columns for opinion, liberal, moderate, and conservative without actually sorting the data. Am I calling the data incorrectly? And why does it make new columns for each ideology instead of sorting into an opinion column with the ideology being the label within the column?

Kurt_Bremser
Super User

In the PROC IMPORT step, you create the dataset WORK.POLITICS, but then you overwrite it in the DATA step.

A dataset named in the DATA statement is created, a dataset named in the SET statement is read.

prizedeye824
Calcite | Level 5

Ohh okay, I think I'm starting to understand. Thank you so much! How do I call the dataset when I'm sorting it then?

Cynthia_sas
SAS Super FREQ
Hi:
All of these topics -- how to read a CSV file, how to use REPLACE, the difference between the DATA statement and a SET statement and how to use PROC SORT, PROC PRINT, PROC FREQ, and some other basic procedures are all covered in the free Programming 1 class (did I mention it is Free?) You can activate the free class using the Get Started button on this site: https://www.sas.com/en_us/training/offers/free-training.html
Cynthia
ballardw
Super User

Why would expect anything to be "sorted" with the code shown? There is nothing in your code that uses or implies a "sorting" step was desired or attempted.

 

Note: This sort of doesn't make sense:

"created extra empty columns for opinion, liberal, moderate, and conservative"

There is nothing in the shown code that would create "columns" (please think VARIABLE because that is not order dependent like a "column") .

HOWEVER since you used the name POLITICS on the DATA statement that is the resulting name of the data set. If the data set POLITICS2 did not exist then you 1) used an empty source for data on the Set statement and your log would show something like

183  data politics;
184     set politics2;
ERROR: File WORK.POLITICS2.DATA does not exist.
185  run;

2)If you did not get that error then somewhere you had a data set Politcs2 and we have no clue what may have been in it but you replaced Politics with Politics2 contents, possibly adding Opinion. Since you have not shown anything related to creating Politics2 we have no way of knowing what was in it.

 

 

andreas_lds
Jade | Level 19

Proc import would create the dataset work.Assignment3, but it is already there, you have not used the replace option so proc import does not replace the existing dataset.

In the next step you want to print work.politics a non-existing dataset. If you want to print the imported data, you have to use the name specified in the import procedure.

Dnka
Calcite | Level 5
Hi, try to add the option "replace" in proc import because the file WORK.ASSIGNMENT3 already exists, you need the option to overwrite it

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 9 replies
  • 1797 views
  • 0 likes
  • 7 in conversation