BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Moksha
Pyrite | Level 9

Hi All,

       I have the following code from 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1hogk0ekd1z62n18xx76ou16unt.htm

Please, help me to understand why fread is reading only John from the file and not entire record. How to make fread to read entire row of each observation?

 

%macro test(outf);
%let filrf=myfile;
%if %sysfunc(fileexist(&outf)) %then %do;
%let rc=%sysfunc(filename(filrf,&outf));
%let fid=%sysfunc(fopen(&filrf));
%if &fid > 0 %then %do;
%let rc=%sysfunc(fread(&fid));
%let rc=%sysfunc(fget(&fid,mystring));
%if &rc = 0 %then %put &mystring;
%else %put file is empty;
%let rc=%sysfunc(fclose(&fid));
%end;
%let rc=%sysfunc(filename(filrf));
%end;
%else %put file does not exist;
%mend test;

 

/*Calling the above macro*/

%test(c:\Address.dat)

 

Output in the log:

%test(c:\Address.dat)

John

 

The contents of test.dat are as follows:

John Garcia            114 Maple Ave.
Sylvia Chung      1302 Washington Drive
Martha Newton    45 S.E. 14th St.

 

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

By default FGET reads to the first space, so it only read John and not beyond.

 

If you use another argument — the LENGTH argument — in the FGET function, you can tell it to read more. https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p1a70mpbj2usaln1r9z4qldliexk.htm

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

By default FGET reads to the first space, so it only read John and not beyond.

 

If you use another argument — the LENGTH argument — in the FGET function, you can tell it to read more. https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p1a70mpbj2usaln1r9z4qldliexk.htm

--
Paige Miller
Moksha
Pyrite | Level 9

Thank you very much PaigeMiller. I have used length now and it's working. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 550 views
  • 1 like
  • 2 in conversation