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

Hi, 

can someone tell me why that 

data new;
do map = 1 to 7;
output;
end;
char_map= put(map,4.);
run;

doesn't do what it should, namely to change from numeric to character/string? (need it to map with another column which is a string... ) Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I think there is an order of operations issue. The output is within the loop and BEFORE the conversion. 

Some concepts:

  • Once there is an explicit OUTPUT statement there is no more implicit OUTPUT
  • No input data set also means no default loop
  • Conversion needs to occur before the record is written to the dataset.

 

data new;
do map = 1 to 7;
         char_map= put(map,4.);
         output;
end;
run;

@newbie69 wrote:

Hi, 

can someone tell me why that 

data new;
do map = 1 to 7;
output;
end;
char_map= put(map,4.);
run;

doesn't do what it should, namely to change from numeric to character/string? (need it to map with another column which is a string... ) Thanks!


 

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Since your PUT function comes after the OUTPUT statement, nothing from PUT is ever output to the data set. Perhaps this is what you want:

 

data new;
    do map = 1 to 7;
        char_map= put(map,4.);
        output;
    end;
run;

Now because PUT comes before output, the results of PUT are written to the data set.

 

And so really, your subject line is wrong, this problem has nothing to do with the data type of the variable. Probably best not to jump to conclusions about the cause, and just simply use a subject line like "PUT statement not working" and ask how to fix it to give the desired result.

--
Paige Miller
Reeza
Super User

I think there is an order of operations issue. The output is within the loop and BEFORE the conversion. 

Some concepts:

  • Once there is an explicit OUTPUT statement there is no more implicit OUTPUT
  • No input data set also means no default loop
  • Conversion needs to occur before the record is written to the dataset.

 

data new;
do map = 1 to 7;
         char_map= put(map,4.);
         output;
end;
run;

@newbie69 wrote:

Hi, 

can someone tell me why that 

data new;
do map = 1 to 7;
output;
end;
char_map= put(map,4.);
run;

doesn't do what it should, namely to change from numeric to character/string? (need it to map with another column which is a string... ) Thanks!


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 481 views
  • 4 likes
  • 3 in conversation