Help using Base SAS procedures

Creating variables dynamically

Contributor sss
Posts: 65

Creating variables dynamically

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 many 120 variables or even mre then that.

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

Posts: 8,169

Creating variables dynamically

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)?

Super User
Super User
Posts: 8,127

Re: Creating variables dynamically

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 ;



   if _n_ >= 5 then stop;


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;


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 ;


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation