BookmarkSubscribeRSS Feed
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;


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


 proc import datafile = "/home/u63565620/Datasets/politics.csv" out = Assignment3;
(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;
I get this error:
 Proc print data = politics;
ERROR: File WORK.POLITICS.DATA does not exist.
I've already imported the file into SAS into a folder called Datasets, so I'm not sure what the issue is
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


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.

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"

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”;


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?

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.

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?

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:
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.




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.

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



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 7 in conversation