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
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
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
Thank you very much PaigeMiller. I have used length now and it's working.
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.
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.