I have a csv data which i am importing in sas , the first column of which has ',' only, what should i use to read in as the values are transcending to next column, i have used dsd,dlm,missover.
Please copy/paste the first few lines of the csv file into a window opened with this button:
And post the code you tried into a window opened with the "little running man" button right next to the one indicated.
Please copy/paste the first few lines of the csv file into a window opened with this button:
And post the code you tried into a window opened with the "little running man" button right next to the one indicated.
ID NAME STATE WEIGHT AGE
, SAM WA 67 12
, TOM TX 90 15
, GINNY MI 89 16
See this:
data want;
infile datalines firstobs=2 dlm=" " dsd truncover;
input id $ name $ state $ weight age;
drop id;
/* or this */
if id = "," then id = " ";
datalines;
ID NAME STATE WEIGHT AGE
, SAM WA 67 12
, TOM TX 90 15
, GINNY MI 89 16
;
Replace the DATALINES keyword in the INFILE statement with your path to the file, and replace the DATALINES block with a RUN statement.
I am not getting the desired output
Id,NAME,STATe,WEIGHT,AGE
,WA,67,12
,TOM,TX,90,15
,GINNY,MI,89,16
this is how the data looks ,i want to read in this into sas.
Open your file with a text editor, and copy/paste the content into a code box, as described earlier. Only when I can be half-way sure I see what you really have, will I work on further code.
please find the attached file.
data want;
infile '/folders/myfolders/test1.txt' firstobs=2 dlm="," dsd truncover;
input id $ name $ state $ weight age;
run;
proc print data=want;
run;
Result:
Beob. id name state weight age 1 WA 67 12 . 2 TOM TX 90 15 3 GINNY MI 89 16
The first data line misses a name.
@archita wrote:
ID NAME STATE WEIGHT AGE
"," SAM WA 67 12
"," TOM TX 90 15
"," GINNY MI 89 16
Why did you post this? It does not look anything at all like the file your attached before.
Here is what those lines look like. Notice how I used the Insert Code button on the forum editor to allow me to paste in the text and have it displayed without being interpretted as paragraphs.
Id,NAME,STATe,WEIGHT,AGE ,WA,67,12 ,TOM,TX,90,15 ,GINNY,MI,89,16
If you don't want to keep the ID variable in your SAS dataset you can use a DROP statement in your data step that reads the text file.
data want;
infile 'myfile.txt' dsd firstobs=2 truncover;
input Id $ NAME $ STATe $ WEIGHT AGE;
drop id;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.