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.
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!
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.