BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I have a numeric variable 'Time'containing some numbers with decimals. I need to convert the variable to chracter form. I am not getting the output i need with my codes shown below. Please help

 

Time

0

0.5

1

1.5

2

2.5

My code;

PKT=put(Time__h_,8.1);

if  PKT='0' then PKT1='PRE-DOSE';

my code generates output;

PKT1

 

0.0

0.5

1.0

1.5

2.0

2.5

 

OUTPUT i need;

PKT1

 

PRE-DOSE

0.5

1

1.5

2

2.5

 

My another code:

PKT=put(Time__h_,8.);

if  PKT='0' then PKT1='PRE-DOSE';

Output generated;

PKT1

 

0

1

1

2

2

3

 

2 REPLIES 2
mohamed_zaki
Barite | Level 11
data want;
set have;
if Time eq 0 then charvar ='PRE-DOSE';
else charvar = STRIP(PUT(TIME, best32.));
run;
PGStats
Opal | Level 21

Use format best. and left align option in PUT function.

 

data have;
input Time;
datalines;
0
0.5
1
1.5
2
2.5
;

data want;
set have;
if Time = 0 then PKT = "PRE-DOSE";
else PKT = put(Time, best. -l);
run;

proc print; run;
PG

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2295 views
  • 2 likes
  • 3 in conversation