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.
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.
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.
I have found it in the local help, so i only can attach you this
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.
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).
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?
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
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.
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.
Thank you, this can be very usefull. I'm gonna try to cut the length and decimals to apply this test.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.