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

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

Capture.PNG

 

 Thanks you.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User
Show what the CSV file looks like. You posted a picture of some word processor table or spreadsheet. A CSV file is a text file. Just copy and paste a the first few lines from the CSV file itself. Do NOT open the CSV file with a spreadsheet program, that could change the data.
ks94
Obsidian | Level 7

it's the label and 3 first lines of csv file 

casecc3countryyearsystemic_crisisexch_usddomestic_debt_in_defaultsovereign_external_debt_defaultgdp_weighted_defaultinflation_annual_cpiindependencecurrency_crisesinflation_crisesbanking_crisis
45NGANigeria20141155,250008,048100crisis
1DZAAlgeria187100,05279800014,1491396000no_crisis
1DZAAlgeria187200,052274000-3,71859297000no_crisis

thanks you.

Patrick
Opal | Level 21

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.

ks94
Obsidian | Level 7

it's done!

it's in .txt

Patrick
Opal | Level 21

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;
Tom
Super User Tom
Super User

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

ks94
Obsidian | Level 7

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1068 views
  • 2 likes
  • 3 in conversation