BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arodriguez
Lapis Lazuli | Level 10

Hi everyone;

I'm trying to do checks over format variables. To do that, I have found a function in SASHelp named FORMAT(format,type) that gives 1 if the format is valid or 0 otherwise.

But when I'm executing the following code SAS don't recognize the FORMAT function

data _NULL_;

rc=format('$char12.','c');

run;

give the next error.

25   rc=format('$char12.','c');

        ------

        68

ERROR 68-185: The function FORMAT is unknown, or cannot be accessed.

There you know, how solve this error or sugest other way to check if a format is valid?

Any tip or help will be welcome.

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12

PROC SQL;

select fmtname into :foundf separated by ' '

from sashelp.vformat

where fmtname = "%upcase(&your_fmt_parm)"

  and fmttype  ="F"

;

Then the value of &sqlobs will be 0 if there are  no formats matching what is in &your_fmt_parm

Of course this crosses the "step-boundary" which might be significant.

It also assumes you have stripped out the length and decimal width from the format parameter and that you want to check for formats rather than informats.

View solution in original post

9 REPLIES 9
Amir
PROC Star

Hi,

I was unable to find a function called "Format" in the Language Elements documentation. Do you have a link to the documentation for it?

Regards,

Amir.

arodriguez
Lapis Lazuli | Level 10

I have found it in the local help, so i only can attach you this

Captura.PNG

Reeza
Super User

This is part of the SAS Component Language (SCL) which I don't think is valid in BASE SAS.

SAS Component Language (SCL) is a programming language designed to facilitate the development of interactive applications using the SAS System. For example, you can use SCL with other SAS software to create data entry applications, to display tables and menus, and to generate and submit SAS source code. SCL is the scripting language behind SAS/AF, SAS/FSP, and SAS/EIS software. Applications developed using SCL with SAS/AF software can be run by users who have only licensed Base SAS software. Previous to Version 7, SAS Component Language was known as SAS Screen Control Language.

Tom
Super User Tom
Super User

Since SAS did not convert this particular SCL function into a foundation SAS function, you might need to instead query the dictionary table FORMATS (or the view SASHELP.VFORMAT).

snoopy369
Barite | Level 11

How do you define 'if a format is valid'?  Are you asking if a format simply exists, or if a format can be applied to a variable legally, or if a format makes sense with a variable's contents, or something else?

Peter_C
Rhodochrosite | Level 12

Among the user defined formats no min/max widths are defined on SASHELP.VFORMAT. However there will be corresponding limits stored in the format catalog. So all formats and informats have limits to their validity.

Also data might not be "of a valid format" especially where it is collected "manually" like in excel

arodriguez
Lapis Lazuli | Level 10

I need to know if a given format exist or not. I'm trying to do a macro and one of the parameters is a format, I'm trying to validate if this given format exist before applied. For example, the parameter can be 20 that is not a correct format value, it needs a dot.

Peter_C
Rhodochrosite | Level 12

PROC SQL;

select fmtname into :foundf separated by ' '

from sashelp.vformat

where fmtname = "%upcase(&your_fmt_parm)"

  and fmttype  ="F"

;

Then the value of &sqlobs will be 0 if there are  no formats matching what is in &your_fmt_parm

Of course this crosses the "step-boundary" which might be significant.

It also assumes you have stripped out the length and decimal width from the format parameter and that you want to check for formats rather than informats.

arodriguez
Lapis Lazuli | Level 10

Thank you, this can be very usefull. I'm gonna try to cut the length and decimals to apply this test.

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
  • 9 replies
  • 1902 views
  • 8 likes
  • 6 in conversation