Did you miss the Ask the Expert session on What Can Formats Do For You? Not to worry, you can catch it on-demand at your leisure.
Watch the webinar
You will learn how to:
Create formats using control data sets, and the value and picture statements.
Create informats using the invalue statement.
Use formats to generate customized reports, including highlighting.
Use formats to group data, input data and combine data.
The questions from the Q&A segment held at the end of the webinar are listed below and the slides from the webinar are attached.
Q&A
What is a 'control' dataset?
A control dataset is a dataset that you create in a form that proc format can read and use. The data set must have at least these three variables: fmtname, start, and label. There's control in option (cntlin=<name of data set>), which means this is going to be an input data set to PROC FORMAT. There is also control out option (cntlout=<name of data set>, on the PROC FORMAT statement. This creates a data set that has the format values in it which we can then modify or update. The option would be used on the PROC FORMAT statement.
Is UPCASE the only option for the INVALUE or is LOWCASE also available?
There is only an UPCASE option, there is not a LOWCASE option.
With the multiplier and a picture format of '0000009', what happens if the resulting value is a non-integer? Does it round to the nearest integer, based on that picture?
Yes. Now a couple of things about numbers. SAS formats always round. User defined formats do not necessarily round, unless you put the round option, which would go on a picture statement. If I have something where I have decimals, then I would add the round option to say, “I do not want to just truncate this. I want to round it.”
If you want to share a SAS dataset with a colleague, how might you send both the dataset and the formats to the external colleague? Is it as simple as creating a control dataset? Or are there any other ways?
If you send a control data set, then the colleague would simply need to use that as a control in data set to recreate the format. You can also use PROC CATALOG to copy the formats from one catalog to another. If you and the colleague are on different operating systems, you need to take that into account.
Is it possible to create a format with the same name of a native one?
No, SAS will not let you do that. Even if you could do that, it would never find it. Say I wanted to create a dollar format. SAS has a dollar format. So, it'll look in SAS to find formats first and it will never see our dollar format. But it will not allow you to create it to begin with.
What is the best option to avoid a rounding problem with decimals when the total percentage sum up to 99.9% or 100.1% instead of 100%?
It depends on exactly what you want to do. If you want to round, you can add the round option. For example, in PROC REPORT, you can apply a different format to summary lines than you apply to the individual report lines. You could adda footnote or a customized break line in PROC REPORT that says percentages may sum to more than 100. So, it really would depend on what you want to do and how you want to round things.
Can I use formats for other style attributes than colors?
Back when I started at SAS, being a former astronomer, I created some formats that used pictures of planets, the Earth and Saturn for inner and outer planets and then I used the style= option to plug those into a PROC TABULATE table. There are also several examples in our Report Writing course about using URLs. I might have summary report that has Australia, Canada, Belgium, UK, and US, and I want to link to the detailed reports on those countries. I can create a format with the URL as the value is the label.
Is using a format for a table lookup more efficient than a merge?
That depends. We used to have a course where we talked about efficiency. One of the slides had a picture of a couple of people having a picnic and the label for the slide was no free lunch. There is always some cost when you are trying to join data from different data sets. One of our former instructors, who is now retired, did some testing with this. They tested ‘if then else’, formats, and arrays. If I have two values, say I want to divide flights into domestic and international and I only operate at 10 airports, ‘if then else’ works perfectly fine. If I have 1000 values, I do not want to type all those values in. The instructor who did the testing said at 100,000 ‘if then else’ crashed. It turns out that ‘if then else’ is good for very small numbers. Formats are good for intermediate ranges up to say 1000, maybe a few more values. Arrays and hash objects are good for larger numbers. Finally, if you get two gigantic data sets, you may be stuck with doing a SQL join or a merge.
Recommended Resources
PROC FORMAT Documentation
SAS Programming 2: Data Manipulation Techniques
SAS Programming 3: Advanced Techniques
Please see additional resources in the attached slide deck.
Want more tips? Be sure to subscribe to the Ask the Expert board to receive follow up Q&A, slides and recordings from other SAS Ask the Expert webinars.
... View more