BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dq1
Fluorite | Level 6 Dq1
Fluorite | Level 6

How to convert 2000to 2k in SAS dataset
Which function we have to use & also how to convert month number to month name using proc format and strip(put,...) Functions. help in getting this

1 ACCEPTED SOLUTION

Accepted Solutions
Dq1
Fluorite | Level 6 Dq1
Fluorite | Level 6
Help me in getting this

View solution in original post

11 REPLIES 11
Dq1
Fluorite | Level 6 Dq1
Fluorite | Level 6
Plz hepl me in getting this
Dq1
Fluorite | Level 6 Dq1
Fluorite | Level 6
Help me in getting this
PaigeMiller
Diamond | Level 26

@Dq1 wrote:
How to convert 2000to 2k in sasdataset

Please help us. Go back to your original post and edit it so that it has a meaningful title/subject. Since this is the SAS community, saying your subject is "Sas" is not helpful or meaningful.

 

You cannot convert 2000 to 2k, the first is a numeric value and the second is a character value. You could create a new variable that contains the text string "2K". A better solution, in my opinion: you could produce a FORMAT that changes the appearance to 2k. 

 

proc format;
    picture thous(round) low-high='000,009.9K' (prefix='$' mult=.01);
run;
data want;
     set have;
     format yourvariablename thous.;
run;

 

--
Paige Miller
Dq1
Fluorite | Level 6 Dq1
Fluorite | Level 6
Could u say in a easy manner of programing
I have a dataset like
Data A;
Input name age sal;
Cards;
Amir 23 4000
Sonu 34 7000
Run;

I want 4000 as 4k
What should I do?
PaigeMiller
Diamond | Level 26

We help you, but you have to help us.

 

Go back to your original post and edit it so that it has a meaningful title/subject. Since this is the SAS community, saying your subject is "Sas" is not helpful or meaningful.

--
Paige Miller
PaigeMiller
Diamond | Level 26
proc format;
    picture thous(round) low-high='000,009.9K' (prefix='$' mult=.01);
run;
data a;
    input name $ age sal;
    format sal thous.;
cards;
Amir 23 4000
Sonu 34 7000
;
--
Paige Miller
Dq1
Fluorite | Level 6 Dq1
Fluorite | Level 6
It's not working ..
Kurt_Bremser
Super User

@Dq1 wrote:
It's not working ..

Make it work.

 

Spoiler
"It's not working" on its own is a VERY dumb statement. It does not tell in ANY way what went wrong or where the outcome did not meet expectations.
In fact it is worthy of the proverbial blonde secretary who needs to be taught again how to handle the coffeemaker after a 10-minute break.
Therefore my terse and snarky answer.
So please tell us WHAT did not work. Include code and logs, and describe where the result does not meet your expectations.
Very important: include example of your data so we know with what the code needs to deal.
PaigeMiller
Diamond | Level 26

Please: 

We help you, but you have to help us.

 

Go back to your original post and edit it so that it has a meaningful title/subject. Since this is the SAS community, saying your subject is "Sas" is not helpful or meaningful.

--
Paige Miller
ballardw
Super User

How should a value like 100 appear for that variable? 15345?

2000 to 2K is a single example. Coding is about providing general rules.

 

Same with month number to month name. Do you want the full name of a month? 3-letter abbreviation? something else?

Reeza
Super User

See this example for your format for 2000 as 2K. 

https://communities.sas.com/t5/SAS-Programming/Million-Format/td-p/440121

 

Regarding month number to name use MONNAME format which will format a SAS date (not month number) to the month name. 

 

data example;
date = '01Jan2021'd;
demoName = put(date, monname3.);
run;

proc print data=example;
run;

proc print data=example;
format date monname3.;
run;

If you want to convert a month number to a date, I'd probably create a fake date out of it using the MDY() function and use the PUT() function. 

 

data example2;
monthNumber = 2;
monthName = put(mdy(monthNumber, 1, 2021), monname3.);
run;

proc print data=example2;
run;

@Dq1 wrote:

How to convert 2000to 2k in SAS dataset
Which function we have to use & also how to convert month number to month name using proc format and strip(put,...) Functions. help in getting this


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 11 replies
  • 1500 views
  • 9 likes
  • 5 in conversation