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

Dear All.

I've a big question.

I'm using SAS 9.3, I've a Macr that I use to check the formats of each variable in a dataset.

This is the Macro:

%macro check_format(lib, ds, var, comp);

  proc sql noprint;

  select informat into: fLength

  from dictionary.columns

  where libname = upcase("&lib") and memname = upcase("&ds") and upcase(name) = upcase("&var");

  quit;

  run;

  %put This is fLength;

  %put &fLength.;

  %if (&comp ^= &fLength) %then %do;

  data _null_;

  put "ERROR: Format of &var is not = &comp, is &fLength ";

  call symput('content_check_STOP','1');

  run;

  %end;

%mend check_format;

If I use this Macro with these paramenters doesn't work:

%check_format(&lib, &dsInOut, SMPLDATE, yymmddn8.);

or:

%check_format(&lib, &dsInOut, SMPLTIME, tod5.);

but the dataset format is correct.

The error that i get is:

ERROR: Format of SMPLDATE is not = yymmddn8., is      

It seems that select informat returns ''.

Could you please help me? Thank you very much.

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

You say "format is correct", but you are selecting informat....?

Classic troubleshooting, best done by yourself.

Take the SQL, run it outside your macro, put the result in a table instead of macro variable etc...

Data never sleeps

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

You say "format is correct", but you are selecting informat....?

Classic troubleshooting, best done by yourself.

Take the SQL, run it outside your macro, put the result in a table instead of macro variable etc...

Data never sleeps
Lorenzom
Calcite | Level 5

Thank you very much.

With select format now works.... you are the best.

Thank you again.

Loko
Barite | Level 11

hello,

the sql returns CAPITAL LETTERS - YYMMDDN8. therefore you need to compare the same things.

You have 2 options:

1) either change the macro -   %if (%upcase(&comp) ^= &fLength) %then %do;

or

2) call the macro with capital letters for the last variable

%check_format(&lib, &dsInOut, SMPLDATE, YYMMDDN8.);


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
  • 1995 views
  • 4 likes
  • 3 in conversation