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!


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 751 views
  • 4 likes
  • 3 in conversation