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

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;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

 

 

 


 

View solution in original post

3 REPLIES 3
Reeza
Super User

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;

 

 

 


 

Reeza
Super User
If you don't want specific variable information, just the number of rows/variables SASHELP.VTABLE is the one you want.

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
  • 3 replies
  • 724 views
  • 2 likes
  • 2 in conversation