BookmarkSubscribeRSS Feed
sss
Fluorite | Level 6 sss
Fluorite | Level 6

hi all,

i want to import data from txt file into sas system.

The size of raw data file is to big,and the length of the record is also to big,what i know is that the values are separated by comma.

What problem i am facing is that i dont know how my variables values it holds in a record.it many 120 variables or even mre then that.

i want to access a variable values and want to create sas data set.

2 REPLIES 2
art297
Opal | Level 21

Does the data file have a header record that contains the variable names?  Have you tried using proc import, indicating that it is a csv file?  Have you looked at the raw file with a text editor like Wordpad (not Notepad, as it has a hard time with large files)?

Tom
Super User Tom
Super User

You can explore the content of your text file with SAS.

If you want to see what it looks like use the LIST statement in a data step.  If there are any non-printable characters in the lines then SAS will show you the hex codes for those characters.

* Dump first 5 lines to the log ;

data _null_;

   infile 'myfile.txt' lrecl=32676 ;

   input;

   list;

   if _n_ >= 5 then stop;

run;

If you know that it is comma delimited then you try just pulling in a few rows into character variables and see what you have .

* Pull in first 50 columns for first 10 rows ;

data sample ;

   infile 'myfile.txt' dsd dlm=','  truncover lrecl=32676 ;

  length x1-x50 ;

   input x1-x50 ;

   if _n_ >= 10 then stop;

run;

If you have figured out how to read it and due to space issues you only want to keep a couple of columns then you could use a KEEP (or DROP) statement or dataset option.

data subset (keep=id age sex);

   infile 'myfile.txt' dsd dlm=',' truncover ;

   input id start end age weight height sex comment ;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 797 views
  • 0 likes
  • 3 in conversation