Help using Base SAS procedures

how to get your data from nonuniform data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

how to get your data from nonuniform data

data phones;
input ph_number;
cards;
2022933923
4162673894
4345768
9848784697
7436348
8643679
7846
7547
7848699499
7552884
5745
3897
2938
4346
4178
8776
9877
5648
4385
2574
4573774889
3266487997
3734874
;
run;


proc format;
picture ph_y 2000-9999="9999)" (prefix="(")
9999999999="999-999-9999"
9999999="999-9999"
;
run;


data ph;
set phones;
ph_n=put(ph_number,ph_y.);
run;

 

 

i need my data like this..

 

 

987-645-3676

       345-7547

             (4777)

Attachment

Accepted Solutions
Solution
‎03-19-2018 07:34 AM
PROC Star
Posts: 263

Re: how to get your data from nonuniform data

Posted in reply to rajeshV89

As @LinusH mentioned, it is just a matter of getting your ranges right, something like

proc format;
picture ph_y 
  2000-9999="9999)" (prefix="(")
  1000000000-9999999999="999-999-9999"
  1000000-9999999="999-9999"
;
run;

View solution in original post


All Replies
Super User
Posts: 5,876

Re: how to get your data from nonuniform data

Posted in reply to rajeshV89
And what is your question more specifically?
Data never sleeps
Occasional Contributor
Posts: 17

Re: how to get your data from nonuniform data

I have that data...from that i need to get data like this...
 
373-373-8368
        273-8478
               (6367)
 
 
 
I have created a format and applied it on the particular variable but i got this
 
 
3733738368
       2738478
            (6367)
 
 
Picture format applied for only 4 digit value..but i need to apply the format for all observations having different digits...
 
That also we can try using substr function...but i don't know why this picture format is not correctly applying on that variable.
Super User
Posts: 5,876

Re: how to get your data from nonuniform data

Posted in reply to rajeshV89

You only defined a range in the first format picture, add 1000000000- and 1000000- respectively will solve your problem.

Data never sleeps
Occasional Contributor
Posts: 17

Re: how to get your data from nonuniform data

Posted in reply to rajeshV89
U r telling that we can't apply that format on this data...right??

If data is like this We can apply that format..

Data new;
Input ph-num;
Cards;
8398647377
7476366
;
Run;




Super User
Posts: 5,876

Re: how to get your data from nonuniform data

Posted in reply to rajeshV89
No I'm telling you that you can, but you need to fix your picture format.
You need to use intervals for all three cases, the first one works since it has a correct interval.
St this point the other two is only valid for no 9999999999 and 9999999, which of course most phone no doesn't match.
Data never sleeps
Solution
‎03-19-2018 07:34 AM
PROC Star
Posts: 263

Re: how to get your data from nonuniform data

Posted in reply to rajeshV89

As @LinusH mentioned, it is just a matter of getting your ranges right, something like

proc format;
picture ph_y 
  2000-9999="9999)" (prefix="(")
  1000000000-9999999999="999-999-9999"
  1000000-9999999="999-9999"
;
run;
Occasional Contributor
Posts: 17

Re: how to get your data from nonuniform data

very thankful to the code given by u...

 

i want become a good programmer in sas...

 

 

i need ur valuable suggestions...

 

kudos in advance..

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 236 views
  • 3 likes
  • 3 in conversation