Hi I want to create "July 2nd Week" in new column,Below is the sample code i tried but i stuck in adding ('th' 'st') dynamically or is there any alternative way to create please help me on this .
data want;
format Today date9. month $3. Week $3. Cat $10.;
Today=today();
month=put(month(Today),monname3.);
Week=put(WEEKDAY(Today),weekday.);
Cat= put(catx(' ',month,Week,'Week'),$10.);
run;
Thanks,
Siva
I have an ordinal format here you can use:
https://gist.github.com/statgeek/6c885f6aea18dbd6caf8
data ordinal_format;
length label $8.;
do number=1 to 300;
numstring = put(number, 16. -l);
if prxmatch('/(?<!1)1\s*$/',numstring) then ending='st';
else if prxmatch('/(?<!1)2\s*$/',numstring) then ending='nd';
else if prxmatch('/(?<!1)3\s*$/',numstring) then ending='rd';
else ending = 'th';
ordstring =catt(numstring, ending);
start=number;
label=ordstring;
fmtname="ordinal_fmt";
type="N";
output;
end;
keep start label fmtname type;
run;
proc format cntlin=ordinal_format;
run;
data want;
do i =1 to 100;
j=i;
output;
end;
format j ordinal_fmt.;
run;
@sivastat08 wrote:
Hi I want to create "July 2nd Week" in new column,Below is the sample code i tried but i stuck in adding ('th' 'st') dynamically or is there any alternative way to create please help me on this .
data want;
format Today date9. month $3. Week $3. Cat $10.;
Today=today();
month=put(month(Today),monname3.);
Week=put(WEEKDAY(Today),weekday.);
Cat= put(catx(' ',month,Week,'Week'),$10.);
run;
Thanks,
Siva
I have an ordinal format here you can use:
https://gist.github.com/statgeek/6c885f6aea18dbd6caf8
data ordinal_format;
length label $8.;
do number=1 to 300;
numstring = put(number, 16. -l);
if prxmatch('/(?<!1)1\s*$/',numstring) then ending='st';
else if prxmatch('/(?<!1)2\s*$/',numstring) then ending='nd';
else if prxmatch('/(?<!1)3\s*$/',numstring) then ending='rd';
else ending = 'th';
ordstring =catt(numstring, ending);
start=number;
label=ordstring;
fmtname="ordinal_fmt";
type="N";
output;
end;
keep start label fmtname type;
run;
proc format cntlin=ordinal_format;
run;
data want;
do i =1 to 100;
j=i;
output;
end;
format j ordinal_fmt.;
run;
@sivastat08 wrote:
Hi I want to create "July 2nd Week" in new column,Below is the sample code i tried but i stuck in adding ('th' 'st') dynamically or is there any alternative way to create please help me on this .
data want;
format Today date9. month $3. Week $3. Cat $10.;
Today=today();
month=put(month(Today),monname3.);
Week=put(WEEKDAY(Today),weekday.);
Cat= put(catx(' ',month,Week,'Week'),$10.);
run;
Thanks,
Siva
Create a custom format:
proc format;
value myxx
1 = '1st'
2 = '2nd'
3 = '3rd'
4 = '4th'
5 = '5th'
6 = '6th'
;
run;
This should suffice, as a month can't stretch over more than six weeks.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.