BookmarkSubscribeRSS Feed
MILKYLOVE
Calcite | Level 5

Hello all,

 

I am trying to convert a csv file to a SAS table using the code below:

 

 

proc import out= work.scores
     datafile ="c:/mydir/scores_*.csv"
     dbms=csv
     replace;
     delimiter="|";
     getnames=YES;
run;

 

 

However the first column of my file is not giving the correct value in the table

CSV FILE:

MILKYLOVE_0-1663753003892.png

Table:

MILKYLOVE_1-1663753151998.png

 

Please help me to get the number right.

 

1 REPLY 1
andreas_lds
Jade | Level 19

The data you have posted is a perfect demonstration why relying on proc import is a bad idea. Instead of reading the first variable as char, the contents of the variable causes sas to set the wrong type. So: don't use proc import write a data step yourself. 

 

Untested:

data work.scores;
  infile "C:/mydir/scores_*.csv" delimiter= "|" firstobs= 2 missover;
  length 
    number $14 
    dab rc construction flotte snt_col pre_col $ 1
    activities $ 200
  ;
  input number -- activities;
run;

If you want to see the real contents of a csv file, open it using a text editor, not Excel.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 1245 views
  • 0 likes
  • 2 in conversation