BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I need some info on the limit of length of character Variable used in PROC FORMAT Value statement. I have some data related to Health Risk Appraisal, where questions are very long (to 200 bytes max). I need to map these questions to a question code for each question in PROC FORMAT. Please let me know if any other way to do this other than in if statement in data step statement.

thanks,
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Explore using PROC FORMAT with CNTLIN= to create your SAS format from a SAS input file. The DOC has all the information you need.

Scott Barry
SBBWorks, Inc.

Recommended Google advanced search arguments, this topic/post:

proc format cntlin site:sas.com

proc format character format site:sas.com
deleted_user
Not applicable
hi Support,

I have checked the documentation, but I am not sure how to refer the lookup value referred to the question in proc format.

I read in all possible questions that I will be getting in the data and assigned a question code for each of the question (which was 250 byte long). I used PROC Format on dataset which had variables.

My code is like this -

data lookup ;
infile inp lrecl = 300 recfm = v delimiter = ',' end = eof dsd truncover ;

length questnin $250.
quesncd $7.
questxtcd $258.
;


input

questnin $
quesncd $
;

questxtcd = Trim(quesncd) || '-' || Trim(questnin) ;

start = questxtcd ;
LABEL = 'KEEP' ;
FMTNAME = '$queskey';

run;

PROC SORT DATA = lookup OUT = FMTOUT NODUPKEY ;
BY start ;

PROC FORMAT CNTLIN=FMTOUT;
run;


So when I read in my raw file - when I refer to CNTLIN format on the raw variable for question we are getting, I am not getting desired output.

Say for example I have a question like this - "HOW MANY HOURS OF SLEEP DO YOU USUALLY GET AT NIGHT?" where I gave QUEST1

So when ever I encounter this question on data, I need to output Quest1 instead of that so long full question. Looks like my reference to PROC Fromat is not working -

HA_QUES_TXT = put(Trim(Left(HA_QUESTION_TEXT)),$QUESKEY.);

HA_QUESTION_TEXT is variable in raw data that I am getting.

Please let me know what else I need to take care to output value "QUEST1".

thanks in Advance,
LG
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
For clarification, this is not SAS Technical Support - that's a different (paid) channel, except maybe the wonderful and thought-provoking Cynthia...

Your SAS code that builds the START variable must match exactly the SAS code that constructs the PUT function argument #1.....they do not appear to be consistent.

So, for self-debugging, have you attempted to analyze the generated format, either with the PROC FORMAT FMTLIB parameter, or better yet, use CNTLOUT= to unload your format and do a PROC PRINT on the SAS-generated file specified on CNTLOUT.

You mention something about "..I need to output Quest1..." but you do not share allof your SAS DATA step code that uses HA_QUES_TXT -- the variable assigned from the PUT function. A match-condition will result in a value of KEEP -- so what do you do then?

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hi Sbb,

Thanks for response. It gave me some direction on how to approach, but not exactly what I needed.

I thought Arg #1 after lookup to PROC FORMAT will result in the short form of Question. But that's not happening. not sure how to get this resolved.

Any ideas would help me a lot and I appreciate it.

thanks,
LG
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Possibly, if you want SAS to return the short-form (your words) on a "match condition", then you need to assign whatever you expect back with the LABEL variable, not the string "KEEP" which only identifies when you have a "match condition" but provides no relief to save some data back from the format.

Also, with creating your CNTLIN= file, after you output the last observation (on END=EOF with the SET stmt), then you want one additional observation for the OTHER= telling SAS what to return on a no-match condition. The DOC explains this technical application / approach.

Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 993 views
  • 0 likes
  • 2 in conversation