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);
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.
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.