Hello,
Please I need your help with a problem I'm having.
I have imported a csv file ... but there are some columns that are missing and also some lines . how to proceed in such a case. I must have 14 variables, but I only have three.
Thank you. Thank you.
my code is:
---------------------------------
proc import datafile="/folders/myfolders/Data_projet_AFRIQUE.csv"
out=Prep.AFRICA
dbms=csv
replace;
getnames=yes;
run;
-------------------------
a picture of the file structure
Thanks you.
Looks like this is not a proper .csv Below works for the attached data.
proc import
datafile="/folders/myfolders/Data_projet_AFRIQUE.txt"
out=Prep.AFRICA
replace;
getnames=yes;
delimiter=';';
guessingrows=max;
run;
it's the label and 3 first lines of csv file
case | cc3 | country | year | systemic_crisis | exch_usd | domestic_debt_in_default | sovereign_external_debt_default | gdp_weighted_default | inflation_annual_cpi | independence | currency_crises | inflation_crises | banking_crisis |
45 | NGA | Nigeria | 2014 | 1 | 155,25 | 0 | 0 | 0 | 8,048 | 1 | 0 | 0 | crisis |
1 | DZA | Algeria | 1871 | 0 | 0,052798 | 0 | 0 | 0 | 14,1491396 | 0 | 0 | 0 | no_crisis |
1 | DZA | Algeria | 1872 | 0 | 0,052274 | 0 | 0 | 0 | -3,71859297 | 0 | 0 | 0 | no_crisis |
thanks you.
Don't open the .csv with Excel. Excel changes things.
You could: If file not too big and data not confidential then just attach the file - else: create a copy of the file, open it with a text editor like Notepad, delete most of the lines, save and then attach the file here.
This will give us your file as close to your actual data as possible.
it's done!
it's in .txt
Looks like this is not a proper .csv Below works for the attached data.
proc import
datafile="/folders/myfolders/Data_projet_AFRIQUE.txt"
out=Prep.AFRICA
replace;
getnames=yes;
delimiter=';';
guessingrows=max;
run;
@ks94 wrote:
it's done!
it's in .txt
Just PASTE the lines from the file into the box that opens when you click on the INSERT CODE icon (it now looks like < / >.
case;cc3;country;year;systemic_crisis;exch_usd;domestic_debt_in_default;sovereign_external_debt_default;gdp_weighted_default;inflation_annual_cpi;independence;currency_crises;inflation_crises;banking_crisis 45;NGA;Nigeria;2014;1;155,25;0;0;0;8,048;1;0;0;crisis 1;DZA;Algeria;1871;0;0,052798;0;0;0;14,14913958;0;0;0;no_crisis 1;DZA;Algeria;1872;0;0,052274;0;0;0;-3,718592965;0;0;0;no_crisis 1;DZA;Algeria;1873;0;0,05168;0;0;0;11,20389701;0;0;0;no_crisis 1;DZA;Algeria;1874;0;0,051308;0;0;0;-3,848560701;0;0;0;no_crisis
The file is NOT a Comma Separated Values file. It is a delimited file with semi-colon as the delimiter. The reason PROC IMPORT thought there were only three variables is because the maximum number of commas in any of the lines was 2. Just tell PROC IMPORT what character to use as the delimiter.
Sorry, there's one detail I forgot to mention. The document has more than 1000 lines but it only shows 100 lines.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.