BookmarkSubscribeRSS Feed
susigaj
Calcite | Level 5


I've seen code in programs where I work where people create a character variable from another character variable using the put function.  What's the point?

For example:

I know here that they are trying to add 50 to the positions 12:13 inside the character variable hrlongid.

length serial $2;

length newsn 8;

serial=put(substr(hrlongid,12,2),$2.);

newsn=serial+50;

substr(hrlongid,12,2)=newsn;

Wouldn't the last statement have to replace positions 12:13 with another character variable?

Why can't serial just be substr(hrlongid,12,2)?

3 REPLIES 3
Haikuo
Onyx | Level 15

seems abundant to me. if they don't have length statement: "length serial $2;", then there is a difference:

with just substr(), the new variable will inherit the same length as the source variable, with put(substr(), $2.) structure, the new var will get the length defined in the informat.

Haikuo

ballardw
Super User

While that may not be the most useful version of Putting a character variable consider:

You have code such as a stock ticker symbol: XYZ and you are combining it with boiler plate text and other variable to create a sentence like:

XYZ had an earnings (increase/decrease) of (value) dollars of the past (interval text).

XYZ could be Put using a custom format for this sentence to read

Alpha Beta Manufacturing, Inc. had ...

Also with a different format the same symbol could use a shorter version such as Alpha Beta, or a much longer piece of text. Not to mention yet another format that would place it into a category:

This placed <company name> among the <top/bottom> 3 companies in <industry type>.

Astounding
PROC Star

Sometimes the answer turns out to be, "They didn't know any better."

It would make a little sense if they used INPUT instead of PUT (and 2. instead of $2.).  That would eliminate messages about character to numeric conversion on the log when computing newsn.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 3 replies
  • 817 views
  • 0 likes
  • 4 in conversation