Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- SAS Training
- /
- Programming 1 and 2 Forum
- /
- Please advise about comma and substr

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-31-2022 07:21 PM
(1217 views)

- Does anyone know where 1 and 6 came from after YearMon?Also in this one it said to include commas and zero decimal places how did they decide comma6. and comma10. instead of any other number?Lastly,
Where am I supposed to be looking for How many storms are in

**PressureGroup**1?I did the following but wrote 3118 and it was wrong. Please advice what is correct answer and where you saw it.

data storm_cat;

set pg1.storm_summary; keep Name Basin MinPressure StartDate PressureGroup;

*add ELSE keyword and remove final condition;

if MinPressure=. then PressureGroup=.;

else if MinPressure<=920 then PressureGroup=1;

else PressureGroup=0;

run;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi:

First, look at the YearMon values, such as with PROC FREQ:

Note that Year is specified in the first 4 positions of the variable and Month value is in positions 6-7, the constant letter M is in position 5. Then, as suggested, review the lecture or read the documentation on the use of the SUBSTR function and the MDY function. Here's the breakdown:

Regarding your second question about "how did they decide" which number to use with the format for comma -- either 6 or 10, that comes down to knowing your data well -- what is the largest possible value, how do you want that value to be displayed, how many extra punctuation characters will be needed to display the largest number. It never hurts to specify a larger value than you think you'll need. Let's say you have a variable called VarX that has a possible minimum value of 3 digits and a possible maximum value of 8 digits. To display the minimum and the maximum using commas as the thousand separator, you need at least 2 commas as shown below:

The largest number that could be displayed without formatting problems is 99999999, which would need a format of comma10. to display as 99,999,999.

Last, 3118 is the total number of rows in the pg1.storm_summary data file. If all the storms were in Pressure Group 1, that would be the right answer. However, there is a procedure which will show you the number of rows that fall into Pressure Group 1 vs Pressure Group 0 or missing. You could either run PROC FREQ on your output data WORK.STORM_CAT or you could run some other procedure. But running PROC FREQ would be the method I would recommend.

Hope this helps point you in the right direction,

Cynthia

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@sann123 wrote:

Does anyone know where 1 and 6 came from after YearMon?

--------------------------

The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for

Allow PROC SORT to output multiple datasets

--------------------------

The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for

Allow PROC SORT to output multiple datasets

--------------------------

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi:

First, look at the YearMon values, such as with PROC FREQ:

Note that Year is specified in the first 4 positions of the variable and Month value is in positions 6-7, the constant letter M is in position 5. Then, as suggested, review the lecture or read the documentation on the use of the SUBSTR function and the MDY function. Here's the breakdown:

Regarding your second question about "how did they decide" which number to use with the format for comma -- either 6 or 10, that comes down to knowing your data well -- what is the largest possible value, how do you want that value to be displayed, how many extra punctuation characters will be needed to display the largest number. It never hurts to specify a larger value than you think you'll need. Let's say you have a variable called VarX that has a possible minimum value of 3 digits and a possible maximum value of 8 digits. To display the minimum and the maximum using commas as the thousand separator, you need at least 2 commas as shown below:

The largest number that could be displayed without formatting problems is 99999999, which would need a format of comma10. to display as 99,999,999.

Last, 3118 is the total number of rows in the pg1.storm_summary data file. If all the storms were in Pressure Group 1, that would be the right answer. However, there is a procedure which will show you the number of rows that fall into Pressure Group 1 vs Pressure Group 0 or missing. You could either run PROC FREQ on your output data WORK.STORM_CAT or you could run some other procedure. But running PROC FREQ would be the method I would recommend.

Hope this helps point you in the right direction,

Cynthia

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you so much Cynthia. That was a really good answer that I was looking for with pictures and all. Really appreciate your help.

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 25. Read more here about **why** you should contribute and **what is in it** for you!

Upcoming Events

- Montreal SAS User Group (MONSUG) Meeting - Fall | 09-Oct-2024
- Ask the Expert: Wie nutze ich das volle Potenzial von SAS® Intelligent Decisioning? | 10-Oct-2024
- Modernize to SAS® Viya® with HPE GreenLake High-Performance, On-Premises, Pay-As-You-Go Solution | 10-Oct-2024
- SAS Bowl XLIV, Model Cards | 16-Oct-2024
- Ask the Expert: Fostering Trustworthy AI Using a Model Card | 17-Oct-2024
- MSUG Presents: | 17-Oct-2024
- BASUG SAS Blowout (In Person) | 18-Oct-2024

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.