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:
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.
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"
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?
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.
With the DATA= option of the PROC SORT statement of the SORT procedure.
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.
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.
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.