Hi Guys,
I have been trying to cut out a portion of the observations, but unsuccessful.
Basically, I have 2 digits, eg. 11, 12, 22, 31,... ....
I want to cut and isolate the first digit under a new variable named "Header"
So header will have 1, 1, 2, 3,
This is the code I used:
DATA CRSP;
SET CRSP;
Length HEADER $1.;
HEADER=SUBSTR(SHRCD,1);
RUN;
However, Header will have no observations.
Please Heap!
Thanks!
Try
HEADER = put(SHRCD,best.-l) ;
If that works then a bunch of the assumptions that we had to make (since you provided no log) could be true.
Assumptions such as
Now why would the above work without invoking function SUBSTR?
That's because the length of HEADER has already been declared as one byte. (Note BTW the statement has to be "length header $1", i.e. no dot after $1 . We are declaring the length here and not assigning a format.)
Transferring a longer character variable's value to a shorter variable results in the value being truncated at the shorter variable's length.
Oh, and "best.-L" means: "write out the numeric value justified left in a format optimal for the field length".
Hope this heaps
Robert
Try
HEADER = put(SHRCD,best.-l) ;
If that works then a bunch of the assumptions that we had to make (since you provided no log) could be true.
Assumptions such as
Now why would the above work without invoking function SUBSTR?
That's because the length of HEADER has already been declared as one byte. (Note BTW the statement has to be "length header $1", i.e. no dot after $1 . We are declaring the length here and not assigning a format.)
Transferring a longer character variable's value to a shorter variable results in the value being truncated at the shorter variable's length.
Oh, and "best.-L" means: "write out the numeric value justified left in a format optimal for the field length".
Hope this heaps
Robert
One more obscure possibility: perhaps SHRCD is character, but contains leading blanks. After the LENGTH statement, simply add:
HEADER = left(SHRCD);
If shrcd is numeric and not character
header=floor(shrcd/10);
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.