BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
iluvsas
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
6 REPLIES 6
Tom
Super User Tom
Super User

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;

iluvsas
Calcite | Level 5

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?

Hima
Obsidian | Level 7

Is the text file in Windows or Unix server?

iluvsas
Calcite | Level 5

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.

JasonDiVirgilio
Quartz | Level 8

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;


iluvsas
Calcite | Level 5

thanks

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1612 views
  • 4 likes
  • 4 in conversation