Hello all,
I have a text file that contains data that looks like below:-
ID Test_1 Test_2 Test_3 Test_4 Test_5
SH101 90.5 88.4 92.3 95.1 90.0
SH102 64.3 64.6 77.4 72.3 71.1
SH103 68.1 69.4 80.6 75.4 70.5
SH104 88.0 77.4 66.2 77.4 67.3
SH105 63.6 70.2 62.1 60.6 72.4
I could import this text file successfully by following query:-
PROC IMPORT OUT=Scores
DATAFILE= "/home/folders/scores.txt"
DBMS=dlm REPLACE ;
RUN;
But I want to convert the data into Sas dataset.
I would be grateful if someone can help me with this issue
Thank you in advance!!
Your PROC IMPORT code is incorrect, you didn't specify a delimiter.
Try one of these instead, which specify a space or tab as a delimiter.
PROC IMPORT OUT=Scores DATAFILE= "/home/folders/scores.txt" DBMS=dlm REPLACE ; DLM= " "; RUN; PROC IMPORT OUT=Scores DATAFILE= "/home/folders/scores.txt" DBMS=dlm REPLACE ; DLM= "09"x; RUN;
In the future please make sure to include significantly more details in your post, specifically, what you're trying to do, the code you used, the log and what is wrong with the approach. You'll get a response much faster.
Why not just use the data step directly like this?
data MyData;
infile "YourPathHere\test.txt" firstobs=2;
input ID $ test_1-test_5;
run;
I tried your solution, which does creates an empty dataset with column names but there are no rows in it from the text file. Any clue why it happens this way? Thanks for the reply...
what exactly is in your txt file? Do you have column headers in there?
Attached is the exact file
Log is as follows:-
@mdhtrivedi wrote:
Hello all,
I have a text file that contains data that looks like below:-
ID Test_1 Test_2 Test_3 Test_4 Test_5
SH101 90.5 88.4 92.3 95.1 90.0
SH102 64.3 64.6 77.4 72.3 71.1
SH103 68.1 69.4 80.6 75.4 70.5
SH104 88.0 77.4 66.2 77.4 67.3
SH105 63.6 70.2 62.1 60.6 72.4
I could import this text file successfully by following query:-
PROC IMPORT OUT=Scores
DATAFILE= "/home/folders/scores.txt"
DBMS=dlm REPLACE ;
RUN;
But I want to convert the data into Sas dataset.
I would be grateful if someone can help me with this issue
Thank you in advance!!
If that PROC IMPORT step worked then you have already created the SAS dataset named SCORES in the WORK library.
What is that you want to do differently?
Checkout the image. You can see I do not get different columns for "ID", "Test_1", "Test_2", "Test_3", "Test_4"; while using PROC IMPORT. They all are been taken as one column only. This is not how I want. I expect to have different columns of each.
Your PROC IMPORT code is incorrect, you didn't specify a delimiter.
Try one of these instead, which specify a space or tab as a delimiter.
PROC IMPORT OUT=Scores DATAFILE= "/home/folders/scores.txt" DBMS=dlm REPLACE ; DLM= " "; RUN; PROC IMPORT OUT=Scores DATAFILE= "/home/folders/scores.txt" DBMS=dlm REPLACE ; DLM= "09"x; RUN;
In the future please make sure to include significantly more details in your post, specifically, what you're trying to do, the code you used, the log and what is wrong with the approach. You'll get a response much faster.
Hi Reeza,
I tried your solution, but both the queries didn't worked. Its still bringing all data into one column. But I ll make sure to add more details in my next post. Thank you for your guidance.
Thanks Reeza, I got my solution by adding DBMS as "TAB" instead of delimiter.
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 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.
Ready to level-up your skills? Choose your own adventure.