BookmarkSubscribeRSS Feed
Maya_QC
Calcite | Level 5

Hi all,

I have to convert many text a file to sas dataset without using DDE. My file is like the following :

Label define  age ///

1 "10 to 20"///

2 "20 to 30 "///

3 "30 to 40 "///

5 "40 to 50"///

6 "50 to 60"///

I tried to read the file and use fread, fget functions to read each line but i couldnot figureout how to create the dataset

%do %while(%sysfunc(fread(&fid1)) = 0);

%let rc=%sysfunc(fread(&fid1));

%let rc=%sysfunc(fget(&fid1,C,200));

Thank you all.

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Not sure what your structure is there, what do the /// reference?  What are the variables?

At a guess:

data want;

     attrib id format=best. age format=$20. otherbit format=$20.;

     infile "...\your_file_here.txt" dlm=" " dsd missover;

     input id age $ otherbit $;

run;

ballardw
Super User

Possible minor change to RW9's code:

dlm " /" and don't bother reading in the otherbit variable unless there is some purpose to that /// other than saying end of line or data section.

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!

How to Concatenate Values

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.

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
  • 444 views
  • 0 likes
  • 3 in conversation