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

- 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
(655 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.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Upcoming Events

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.