I have a text file with the below format.
patient_id|desc
1|active
34|closed
33|joined on 23-apr-12
patient|01JAN2011|3
The first row is a header variable. The last row is a trailer with the file name, date the text file was sent and the record count.
I have loaded the data into a sas dataset. In that process , I also want to check if the record count in the trailer matches with the data that gets loaded into the sas dataset. I skip the trailer record when I load my data into the patient sas dataset.
If i could incorporate this logic into a macro and read the macro into the main sas job that loads the data into a dataset, it would be better. I need to do this check on 7 files.
Please advise as I am a beginner in sas and never used macros....
Doesn't sound like a macro issue.
For example here is a data step to read your example data.
data want ;
infile cards firstobs=2 dlm='|' truncover ;
input patient ?? :9. status $40. ;
if patient ne . then do;
recordno+1;
output;
end;
else do;
put _infile_ / recordno= ;
end;
cards;
patient_id|desc
1|active
34|closed
33|joined on 23-apr-12
patient|01JAN2011|3
run;
Thanks Tom. I have already read the txt file and created a sas dataset. I want to write a macro to do the quality check by comparing the trailer record count to the number of records in the dataset after the load. How do i check this?
Is the text file in Windows or Unix server?
The txt file is on a unix server. I do know how to load the txt file into a dataset. I want to know how to compare and validate the dataset records count with the trailer record count (here trailer count = 3) using a sas macro.
When you read the trailer record, create a macro variable using CALL SYMPUT('yourmacrovar', rowcountvar);
Create yourself a little macro called NumObs to check the number of observations in a dataset:
%macro numobs(dsn);
%global numobs;
%let dsid=%sysfunc(open(&dsn));
%let numobs=%sysfunc(attrn(&dsid,nobs));
%let rc=%sysfunc(close(&dsid));
%mend numobs;
Then compare the two macro variables:
%if &yourmacrovar=&numobs %then %let validated=YES;
%else %let validated=NO;
thanks
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.