BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I need SAS Code that does the following:
1. Checks if selected columns are in fact in the Data Table
2. Checks if above columns are in certain formats
3. Checks if the data in the above columns are usable
4. If the table fails any of these tests, an detailed error should be given and the process must be stopped.

I'm adding this code to "Idiot Proof" our current SAS Macros. I have no idea where to start...

The only one that I know how to do is point 3.
5 REPLIES 5
Patrick
Opal | Level 21
For point 1 and 2: Query the dictionary tables (or the corresponding views in SASHELP). The dictionary table is either 'tables' or 'columns' - never sure about this.
LinusH
Tourmaline | Level 20
Another possibility is to use data step functions to query the table directly.
For point 4 I guess you are into some extensive if-then logic, where you combine the type of error (point 1-3) with the information retrieved by point 3 together with original information you got (table/column name etc).

/Linus
Data never sleeps
deleted_user
Not applicable
Suppose 'Clnmsg' is the table you want to query.
Use proc contents to create a table containing structure of 'clnmsg' dataset.
you can use the keep option to keep only the required columns.

proc contents data = clnmsg out = structure(keep = memname name type length format formatl formatd informat informl informd);
run;

you can now freely query the 'structure' dataset to check the datatypes, formats etc.
Cynthia_sas
SAS Super FREQ
Hi:
The dictionary tables already exist. You don't necessarily need to create an output data set from PROC CONTENTS. If you search previous forum postings for "dictionary.tables" and "dictionary.columns", you should find some other examples.

cynthia
[pre]
proc sql;
create table structure as
select libname, memname, name, type, length,
format, informat, label
from dictionary.columns
where libname = 'SASHELP' and
memname = 'SHOES';
run;
quit;

proc print data=work.structure;
run;
[/pre]
deleted_user
Not applicable
i forgot to mention,

memname : contains tablename
name : contains variablename
type : contains variable type (1 for numeric, 2 for character)
length : contains length
format : contains formatname
formatl : contains format length
formatd : contains number of digits post decimal

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
  • 5 replies
  • 970 views
  • 0 likes
  • 4 in conversation