DATA Step, Macro, Functions and more

Changing the length of a character variable in DATA STEP?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 99
Accepted Solution

Changing the length of a character variable in DATA STEP?

 

/*Append all table*/
data spay.contactless;
	set usage transactions active ratio;
run;

all the 5 tables above has a variable _NAME_. However when I append them by row as above, the variable _NAME_ has truncated values.

How can I redefine the length for _NAME_?

Or how can I create another variable as below?

/*Combine for Contactless Table*/
data spay.contactless;
  input new_NAME_ $20;
	set spay.usage spay.transactions spay.active spay.ratio;
	new_NAME_ = _NAME_; *copy _NAME_ to new_NAME_;
run;

Accepted Solutions
Solution
‎03-09-2017 11:17 PM
Super User
Posts: 5,081

Re: Changing the length of a character variable in DATA STEP?

SImplest:

 

/*Append all table*/
data spay.contactless;
length _name_ $20; set usage transactions active ratio; run;

 

Just make sure the LENGTH statement appears before the SET statement. 

View solution in original post


All Replies
Solution
‎03-09-2017 11:17 PM
Super User
Posts: 5,081

Re: Changing the length of a character variable in DATA STEP?

SImplest:

 

/*Append all table*/
data spay.contactless;
length _name_ $20; set usage transactions active ratio; run;

 

Just make sure the LENGTH statement appears before the SET statement. 

Super User
Super User
Posts: 7,401

Re: Changing the length of a character variable in DATA STEP?

_NAME_ is a SAS internal variable name which you get from, for example, a transpose output.  Why would you want to be using this further, use your own variables or you might encounter problems later on.  Also, why do you have several sets of the same data which need to be put back together?  If your data is in one dataset - and we have discussed this in one of your other posts - then this question no longer exists.  Your basically just creating blocks of work for yourself needlessly.

Super User
Posts: 10,497

Re: Changing the length of a character variable in DATA STEP?

If you had read the log after running the step combining the sets you would have seen this message:

 

WARNING: Multiple lengths were specified for the variable _NAME_ by input data set(s). This may cause

truncation of data.

 

Which tells you what the cause was.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 122 views
  • 1 like
  • 4 in conversation