DATA Step, Macro, Functions and more

character length in variable

Reply
Occasional Contributor
Posts: 10

character length in variable

hi there!.

how to print entire content of particular character varible

for example i need to print like " my name is alphapet and place is world " on entire column

PROC Star
Posts: 1,400

Re: character length in variable

Posted in reply to navinrraj

The length of a character variable is set the first time the data step meets the variable. Therefore, make sure that the length of the variable is large enough to meet your needs. 

 

As a small example, here:

 

data test1;
   string="abc";output;
   string=" my name is alphapet and place is world ";output;
run;

the length of String is three. Therefore the string you want to have in a variable is truncated. Instead, we can make sure the no truncation happens by setting a large enough length like this

 

data test2;
   length string $200;
   string="abc";output;
   string=" my name is alphapet and place is world ";output;
run;
Occasional Contributor
Posts: 10

Re: character length in variable

Thanks and how to do it tat from infile methid
Super User
Posts: 10,571

Re: character length in variable

Posted in reply to navinrraj

Post the code you already have, and we can show you where to improve it.

If you read from an external file, include an example for that.

See my footnotes for hints on posting code; use the {i} button to post lines from the external file.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 10

Re: character length in variable

[ Edited ]
Posted in reply to KurtBremser

data breakfast;

length items $20;

length description $85;

infile"/home/naveence0/food.txt" dlm='|';

input items$ price description$ calorieskl;

run;

proc print data = breakfast;

data breakfast;

set breakfast;output;

format price DOLLAR10.2;

;

run;

proc print data= breakfast;

Super User
Posts: 10,571

Re: character length in variable

Posted in reply to navinrraj

You can simplify your code by using informats with a colon, and formatting price in the same step:

input items :$20. price description :$85. calorieskl;
format price dollar10.2;

The length statements can now be omitted.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 5 replies
  • 46 views
  • 0 likes
  • 3 in conversation