How to import the attached csv files and keep the "." , these is just the sample data and it delimited by "|" and contain a value "N|A"
"VAR1"|"VAR2"|"VAR3" "(-)"|"NA"|"A" "-"|"N|A"|"B" "."|""|"C" ""|"na"|"D"
The below code will convert the "." as missing value, but I want the value VAR1 in row 3 is "."
options missing="*"; proc import datafile="test.csv" out=t1 dbms=csv replace; delimiter='|'; getnames=yes; run; data t2; infile "test.csv" delimiter='|' dsd flowover firstobs=2 missover /*truncover*/; input VAR1 :$20. VAR2 :$10.; run;
Thank you very much.
There is no need to "import" a CSV file. Just write the data step needed to READ the file.
To avoid the normal conversion of a single period to a missing value you need to read the value using the $CHAR informat instead of the default $ informat.
data t2;
infile "test.csv" dsd dlm='|' truncover firstobs=2 ;
input VAR1 :$char20. VAR2 :$char10. var3 :$char1.;
run;
Result
Obs VAR1 VAR2 var3 1 (-) NA A 2 - N|A B 3 . C 4 na D
PS You can only have one of FLOWOVER MISSOVER and TRUNCOVER. The last one listed will "win". The default is FLOWOVER. You almost never want the strange behavior of MISSOVER. So use TRUNCOVER when reading a delimited text file that might have an empty value for the last value on the line.
There is no need to "import" a CSV file. Just write the data step needed to READ the file.
To avoid the normal conversion of a single period to a missing value you need to read the value using the $CHAR informat instead of the default $ informat.
data t2;
infile "test.csv" dsd dlm='|' truncover firstobs=2 ;
input VAR1 :$char20. VAR2 :$char10. var3 :$char1.;
run;
Result
Obs VAR1 VAR2 var3 1 (-) NA A 2 - N|A B 3 . C 4 na D
PS You can only have one of FLOWOVER MISSOVER and TRUNCOVER. The last one listed will "win". The default is FLOWOVER. You almost never want the strange behavior of MISSOVER. So use TRUNCOVER when reading a delimited text file that might have an empty value for the last value on the line.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.