Hi,
I think having not programmed anything new lately has really deteriorated my skills.
I have a really long program. I want to create a secondary QA dataset which captures all the table names, observations numbers, variable numbers as the program is running. This way in each step, I can compare observation numbers to ensure that they all match. This needs to be automated which is why I am asking for help here.
How do I do this in a macro? I know how to set up macro variables to do this (see below). However, I cannot figure out how to do it in a dataset.
%MACRO OBSNVARS(DS);
%GLOBAL DSET NVARS NOBS;
%LET DSET=&DS;
/* OPEN DATA SET PASSED AS THE MACRO PARAMETER */
%LET DSID = %SYSFUNC(OPEN(&DSET)); /*1 IF DATASET EXISTS; 0 IF DATASET DOES NOT EXIST*/
/* IF THE DATA SET EXISTS, GET THE NUMBER OF OBSERVATIONS */
/* AND VARIABLES AND THEN CLOSE THE DATA SET */
%IF &DSID %THEN
%DO;
%LET NOBS =%SYSFUNC(ATTRN(&DSID,NOBS));
%LET NVARS=%SYSFUNC(ATTRN(&DSID,NVARS));
%LET RC = %SYSFUNC(CLOSE(&DSID));
%END;
/* OTHERWISE, WRITE A MESSAGE THAT THE DATA SET COULD NOT BE OPENED */
%ELSE %PUT OPEN FOR DATA SET &DSET FAILED - %SYSFUNC(SYSMSG());
%MEND OBSNVARS;
Would it be easier to hit SASHELP.VCOLUMN instead and retrieve that information?
Would it also make sense to pass two data set names in so it can compare the record counts and let you know if there's an issue?
@lei wrote:
Hi,
I think having not programmed anything new lately has really deteriorated my skills.
I have a really long program. I want to create a secondary QA dataset which captures all the table names, observations numbers, variable numbers as the program is running. This way in each step, I can compare observation numbers to ensure that they all match. This needs to be automated which is why I am asking for help here.
How do I do this in a macro? I know how to set up macro variables to do this (see below). However, I cannot figure out how to do it in a dataset.
%MACRO OBSNVARS(DS); %GLOBAL DSET NVARS NOBS; %LET DSET=&DS; /* OPEN DATA SET PASSED AS THE MACRO PARAMETER */ %LET DSID = %SYSFUNC(OPEN(&DSET)); /*1 IF DATASET EXISTS; 0 IF DATASET DOES NOT EXIST*/ /* IF THE DATA SET EXISTS, GET THE NUMBER OF OBSERVATIONS */ /* AND VARIABLES AND THEN CLOSE THE DATA SET */ %IF &DSID %THEN %DO; %LET NOBS =%SYSFUNC(ATTRN(&DSID,NOBS)); %LET NVARS=%SYSFUNC(ATTRN(&DSID,NVARS)); %LET RC = %SYSFUNC(CLOSE(&DSID)); %END; /* OTHERWISE, WRITE A MESSAGE THAT THE DATA SET COULD NOT BE OPENED */ %ELSE %PUT OPEN FOR DATA SET &DSET FAILED - %SYSFUNC(SYSMSG()); %MEND OBSNVARS;
Would it be easier to hit SASHELP.VCOLUMN instead and retrieve that information?
Would it also make sense to pass two data set names in so it can compare the record counts and let you know if there's an issue?
@lei wrote:
Hi,
I think having not programmed anything new lately has really deteriorated my skills.
I have a really long program. I want to create a secondary QA dataset which captures all the table names, observations numbers, variable numbers as the program is running. This way in each step, I can compare observation numbers to ensure that they all match. This needs to be automated which is why I am asking for help here.
How do I do this in a macro? I know how to set up macro variables to do this (see below). However, I cannot figure out how to do it in a dataset.
%MACRO OBSNVARS(DS); %GLOBAL DSET NVARS NOBS; %LET DSET=&DS; /* OPEN DATA SET PASSED AS THE MACRO PARAMETER */ %LET DSID = %SYSFUNC(OPEN(&DSET)); /*1 IF DATASET EXISTS; 0 IF DATASET DOES NOT EXIST*/ /* IF THE DATA SET EXISTS, GET THE NUMBER OF OBSERVATIONS */ /* AND VARIABLES AND THEN CLOSE THE DATA SET */ %IF &DSID %THEN %DO; %LET NOBS =%SYSFUNC(ATTRN(&DSID,NOBS)); %LET NVARS=%SYSFUNC(ATTRN(&DSID,NVARS)); %LET RC = %SYSFUNC(CLOSE(&DSID)); %END; /* OTHERWISE, WRITE A MESSAGE THAT THE DATA SET COULD NOT BE OPENED */ %ELSE %PUT OPEN FOR DATA SET &DSET FAILED - %SYSFUNC(SYSMSG()); %MEND OBSNVARS;
ABSOLUTELY. Thank you.
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.
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.