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

Hi All,

 

The formatted values were gettng truncated to a length of 20, when the data have the values which were not covered in below expected values.

Ex: Raw data: "Once every 6 months in 2 cycles 15 days apart", which is not present in the proc format.

Formatted value: "Once every 6 months" instead of full length value.

 

Could you please help on this.


PROC FORMAT LIBRARY=work;
 Value $CMFREQ

 "1" = "BID"
 "2" = "TID"
 "3" = "QID"
 "4" = "QD"
 "5" = "QM"
 "6" = "PRN"
 "7" = "Twice in the morning"
 "8" = "Twice in the evening"
 "9" = "Before meals"
"Q 6 months"= "Q6M"
;
run;


data cm;
length cmfreq $100.;
set raw.cm;
where cmfreqot ne '';
cmfreq = put(cmfreqot, $CMFREQ.);

keep cmfreqot cmfreq;
run;

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, tricky one.  Had to think about it for a while.  Simplest way is to put other= and specify the format:

proc format library=work;
 value $cmfreq
    "1" = "BID"
    "2" = "TID"
    "3" = "QID"
    other=[$100.]
    ;
run;

data cm;
  length cmfreq cmfreqtot $100.;
  infile datalines dlm="¬" missover;
  input cmfreqtot $;
  cmfreq=put(cmfreqtot, $CMFREQ.);
datalines;
3
A really long string which should push the twenty character bounds
;
run;

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, tricky one.  Had to think about it for a while.  Simplest way is to put other= and specify the format:

proc format library=work;
 value $cmfreq
    "1" = "BID"
    "2" = "TID"
    "3" = "QID"
    other=[$100.]
    ;
run;

data cm;
  length cmfreq cmfreqtot $100.;
  infile datalines dlm="¬" missover;
  input cmfreqtot $;
  cmfreq=put(cmfreqtot, $CMFREQ.);
datalines;
3
A really long string which should push the twenty character bounds
;
run;
devarayalu
Fluorite | Level 6

Many Thanks for your swift response. Issue solved now.

Much appreicated.

BrunoMueller
SAS Super FREQ

Hi

 

Another way would be, to specify the default length for the format. See sample below.

 

proc format library=work;
 value $cmfreq (default=100)
    "1" = "BID"
    "2" = "TID"
    "3" = "QID"
    ;
run;

data cm;
  infile datalines dlm="¬" truncover;
  input cmfreqtot $100.;
  cmfreq=put(cmfreqtot, $CMFREQ.);
datalines;
3
2
1
A really long string which should push the twenty character bounds
abc
;

Bruno

Tom
Super User Tom
Super User

You can define a default width when you define the format.

PROC FORMAT LIBRARY=work;
 value $CMFREQ (default=100) 
 "1" = "BID"
 "2" = "TID"
 "3" = "QID"
 "4" = "QD"
 "5" = "QM"
 "6" = "PRN"
 "7" = "Twice in the morning"
 "8" = "Twice in the evening"
 "9" = "Before meals"
 "Q 6 months"= "Q6M"
;
run;

Or you can specify the width when you use the format.

cmfreq = put(cmfreqot, $CMFREQ100.);
Jagadishkatam
Amethyst | Level 16
PLease try the default=100 in proc format

like below

PROC FORMAT LIBRARY=work;
 Value $CMFREQ (default=100)
 "1" = "BID"
 "2" = "TID"
 "3" = "QID"
 "4" = "QD"
 "5" = "QM"
 "6" = "PRN"
 "7" = "Twice in the morning"
 "8" = "Twice in the evening"
 "9" = "Before meals"
"Q 6 months"= "Q6M"
;
run;
Thanks,
Jag
devarayalu
Fluorite | Level 6

Thank you Jagadish

Ksharp
Super User
cmfreq = put(cmfreqot, $CMFREQ100.);

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 7378 views
  • 5 likes
  • 6 in conversation