DATA Step, Macro, Functions and more

How to use length command with multiple variables

Reply
Contributor
Posts: 22

How to use length command with multiple variables

Hello

I am now trying to use length command with several hundreds of variables.

Since the number of variables are too many, I want to express variables in a short and efficient way.

Following is the code I designed.

 

length name $ 100 secid $ 100 (time1-204) ($ 100);

 

I know something is wrong on the last part of the code, but can't figure out how to fix it.

 

Please give me some help.

PROC Star
Posts: 1,190

Re: How to use length command with multiple variables

Close. Do like this

 

length name $ 100 secid $ 100 time1-time204 $ 100;
Super User
Posts: 9,580

Re: How to use length command with multiple variables


draycut wrote:

Close. Do like this

 

length name $ 100 secid $ 100 time1-time204 $ 100;

Beat me by 15 seconds Smiley Happy

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 9,580

Re: How to use length command with multiple variables

Try

length name $ 100 secid $ 100 time1-time204 $ 100;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 22

Re: How to use length command with multiple variables

Posted in reply to KurtBremser

1.png

Thanks for the quick reply!

But this is what I got with no outcome..

Do you know what is another error that needs to be fixed?

PROC Star
Posts: 1,190

Re: How to use length command with multiple variables

You probably do not see any ERRORS in your log, only NOTES that the variables are uninitialized. You probably need an INPUT Statement after your INFILE Statement.

Super User
Posts: 9,580

Re: How to use length command with multiple variables

A SAS log is pure text. To post it here, just use copy/paste into a window opened with the {i} button of the main Rich Text posting window.

The same goes for SAS code, the "little running man icon" will even imitate most of the coloring fo the SAS Enhanced Editor.

 

And yes, you're missing an input statement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
PROC Star
Posts: 1,328

Re: How to use length command with multiple variables

Posted in reply to KurtBremser

specifying the length of 100 bytes does not require to be done one  by one in a length statement for each variable or variable list:

data w1;
set sashelp.class(drop=name);
length name  secid  time1-time204 $ 100;
run;

proc contents data=w1;
run;
Super User
Super User
Posts: 9,211

Re: How to use length command with multiple variables

"with several hundreds of variables." - this sounds bad already.  Does the data come from Excel by any chance?  Observations not columns is the way forward.

Ask a Question
Discussion stats
  • 8 replies
  • 109 views
  • 6 likes
  • 5 in conversation