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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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