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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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