DATA Step, Macro, Functions and more

FORMAT function

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 144
Accepted Solution

FORMAT function

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.


Accepted Solutions
Solution
‎12-19-2013 09:00 AM
Valued Guide
Posts: 2,175

Re: FORMAT function

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


All Replies
Super Contributor
Posts: 282

Re: FORMAT function

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.

Frequent Contributor
Posts: 144

Re: FORMAT function

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

Captura.PNG

Super User
Posts: 17,863

Re: FORMAT function

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.

Super User
Super User
Posts: 6,502

Re: FORMAT function

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).

Regular Contributor
Posts: 244

Re: FORMAT function

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?

Valued Guide
Posts: 2,175

Re: FORMAT function

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

Frequent Contributor
Posts: 144

Re: FORMAT function

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.

Solution
‎12-19-2013 09:00 AM
Valued Guide
Posts: 2,175

Re: FORMAT function

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.

Frequent Contributor
Posts: 144

Re: FORMAT function

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 462 views
  • 8 likes
  • 6 in conversation