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

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
Quartz | Level 8

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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 146 views
  • 1 like
  • 2 in conversation