BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shyamtawde
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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.

shyamtawde
Fluorite | Level 6
Thank you so much
The code is working ##- Please type your reply above this line. No
attachments. -##

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 608 views
  • 0 likes
  • 3 in conversation