BookmarkSubscribeRSS Feed
Pritish
Quartz | Level 8
Hello All,

I have got a dataset which is in a text file and has around 400 variables and more than 10,000 records. I want to import this file in SAS and I will be using Infile for importing the dataset. But for using Infile we need to define the variable names in the dataset which in my case is not defined.

Now as there are around 400 variables is there any easy way of defining the variables in the Infile format ?

(Plz guide me if I have posted this question in a wrong section)

Waiting for the reply.

Thanks! Message was edited by: Pritish
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Given your post, it's unclear how you would expect to associate variable names, other than having the information either in the input-data file (typically as the first/header row) or by using logic in your SAS DATA step (you mentioned INFILE) program code-piece?

Suggest you share a simplified data-sample (raw input) and also share what you expect to see (SAS dataset/member/table result) as the outcome from your INFILE processing?


Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

intro data step programming site:sas.com

proc import site:sas.com

input data step site:sas.com
Pritish
Quartz | Level 8
Scott,

Thanks for the reply. Here is a sample raw input which you are looking for:

0.2,0.5,31,46,57,9.4,7.5
1.3,2.3,20,55,91,4.3,3.0

I have comma separated value in my txt file. I have in all around 400 variable with a similar values. So what I am trying to do is to import the dataset in SAS using Infile statement. Now the format for infile statement is like

DATA WORK.dataset.name;
INFILE "Path.txt" DELIMITER=','x;
INPUT var1 var2 var3;
RUN;

I want my dataset in SAS to be like:

Var1 Var2 Var3 Var4 ..... Varn
0.2 0.5 31 46 ....
1.3 2.3 20 55

It's not feasible to write all 400 variable name in the Input step right ?

So can you suggest me a better way for this ?

Thanks for the help.
art297
Opal | Level 21
Why don't you try proc import? E.g.,:

PROC IMPORT OUT= WORK.WANT
DATAFILE= "c:\path.txt"
DBMS=DLM REPLACE;
DELIMITER='2C'x;
GETNAMES=NO;
DATAROW=1;
RUN;

HTH,
Art
Pritish
Quartz | Level 8
Art,

Thanks for the reply. It really worked.

Thanks for the help !
Peter_C
Rhodochrosite | Level 12
> Hello All,
>
> I have got a dataset which is in a text file and has
> around 400 variables and more than 10,000 records. I
> want to import this file in SAS and I will be using
> Infile for importing the dataset. But for using
> Infile we need to define the variable names in the
> dataset which in my case is not defined.
>
> Now as there are around 400 variables is there any
> easy way of defining the variables in the Infile
> format ?
>
> (Plz guide me if I have posted this question in a
> wrong section)
>
> Waiting for the reply.
>
> Thanks!
>
> Message was edited by: Pritish

data output_dataset ;
infile 'where.ever' dsd ......... what ever options needed like lrecl= and firstobs= ;
length var1-var400 8 ;
input var1-var400 ;
run ;
if var25 is string length 10, then your code might change only at
length var1-var24 8 var25 $10 var25-var400 8 ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 2546 views
  • 0 likes
  • 4 in conversation