Hello everyone,
my observation is like 'Absolute Sexual Abstinences,Use of condom with spermicide'
and I have provided the length as 57 also, still in results its showing like 'Absolute'.
below is the code:
Data CH;
infile " ";
input SUBJID$ FORM$ CMSTAT$ CMSPECIFY$;
LENGTH SUBJID$ 5 FORM$ 20 CMSTAT$ 3 CMSPECIFY$ 57;
run;
title "Frequency table of Contraceptive Hisory";
Proc freq data = work.CH;
tables CMSTAT CMSPECIFY/ NOCUM;
run;
Another method to set the lengths is the use of formats in the input statement:
data ch;
infile " ";
input subjid :$5. form :$20. cmstat :$3. cmspecify :$57.;
run;
The colon modifier prevents true formatted input (where exactly the number of bytes as stated in the format are read); instead it is still list input, and the delimiters are observed.
AVOID USING CAPITILISATION!
The reason being is because it is like shouting at the reader.
Now, in your problem, you have defined the length after the input statement. If a variable is not defined, then it will be defined with default values at the first instance it is used. So the datastep gets to the input and finds the cmspecify variable is not defined, so assigns it as $8 which is the default for character strings. Here I move the length before the input, so the first time the compiler sees the variable is when the length is defined:
data ch; length subjid $5 form $20 cmstat $3 cmspecify $57; infile " "; input subjid $ form $ cmstat $ cmspecify $; run; title "Frequency table of Contraceptive Hisory"; proc freq data=ch; tables cmstat cmspecify / nocum; run;
You can get a code window up by clicking the {i} on the toolbar above post area.
Another method to set the lengths is the use of formats in the input statement:
data ch;
infile " ";
input subjid :$5. form :$20. cmstat :$3. cmspecify :$57.;
run;
The colon modifier prevents true formatted input (where exactly the number of bytes as stated in the format are read); instead it is still list input, and the delimiters are observed.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.