I'm not sure which approach you finally took and knowing that will be necessary to provide the best advice. If you know have a series of 1 and 0 coded variables, for example, you would probably be best assigning variable labels rather than trying to use a format and only possibly use a format to show the values of 1 and 0 as checked or not checked.
What does your final datafile cuurently look like. Can you provide a couple of its lines?
Thanks Tom and Art.
Tom, your version was perfect for analysis. I can now effectively count the frequencies of all different interventions. This is great!
Art, your version is perfect for manipulating the data to send out to agencies. Please see the version i used below . Thanks so Much!
data Pre.Q60 (keep=Agency_Name Case_No Case_FirstName Case_LastName cra60_);
set Pre.Presheet1;
i=1;
do while (scan(cra60,i,";") ne "");
cra60_=input(scan(cra60,i,";"),12.);
output;
i+1;
end;
Proc sort data= Pre.Q60;
by Case_No;
proc transpose
data=Pre.Q60
out=Pre.Q60 (drop=_:)
prefix= cra60_;
var cra60_ ;
format cra60_ cra60format.;
by Case_No;
run;
I'm still just guessing as to what your resulting file looks like, but I think that the following (or something quite similar) is what you will need to finish the task:
data labels;
informat response $50.;
input Code $ Response &;
cards;
cra60_1 Intensive Home Based Family PreservationServices
cra60_2 Family has been provided Emergency Shelter
cra60_3 Family has been safely moved to a DV Shelter
cra60_4 Caretaker has been moved to a safe environment
cra60_5 Authorization of Emergency Food/Cash
cra60_6 Judicial Intervention
cra60_7 Order of Protection
cra60_8 Law Enforcement involvement
cra60_9 Emergency Medical Services
cra60_10 Crisis Mental Health Services have beenprovided
cra60_11 Emergency In-patient Mental Health Serviceshave been provided
cra60_12 Immediate Supervision/Monitoring
cra60_13 Emergency Alcohol Abuse Services have beenprovided
cra60_14 Emergency Drug Abuse Services
;
proc sql noprint;
select "label "||Code||'="'||Response||'"'
into :labels
separated by " "
from labels
;
quit;
/*What I think you currently have*/
data have;
input cra60_1-cra60_14;
cards;
1 0 1 0 1 1 1 1 1 1 0 1 0 1
0 1 1 1 0 0 0 1 1 0 1 1 1 1
;
data want;
set have;
&labels.;
run;
The INPUT() function is used to convert the characters in the variable NEXT to a number in the variable I.
The IF statement is so that only numbers will cause SAS to execute the assignment statement. You might want to make it more specific than just testing for not missing. Try IF 1 <= I <= dim(cra60_) THEN ....
When I is missing the PUT statement will run and you will see in the log the values of the variables. The most likely characters that you might see that could have caused the errors you got before are formatting characters like tab,line feed or carriage return. The HEX code representation of those three characters are 09,0A and 0D , respectively.
Here is a link to the manual page for $HEX format.
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000205099.htm
Thanks Tom and Art.
Tom, your version was perfect for analysis. I can now effectively count the frequencies of all different interventions. This is great!
Art, your version is perfect for manipulating the data to send out to agencies. Please see the version i used below . Thanks so Much!
data Pre.Q60 (keep=Agency_Name Case_No Case_FirstName Case_LastName cra60_);
set Pre.Presheet1;
i=1;
do while (scan(cra60,i,";") ne "");
cra60_=input(scan(cra60,i,";"),12.);
output;
i+1;
end;
Proc sort data= Pre.Q60;
by Case_No;
proc transpose
data=Pre.Q60
out=Pre.Q60 (drop=_:)
prefix= cra60_;
var cra60_ ;
format cra60_ cra60format.;
by Case_No;
run;
It is another way.
*Get magic number; data _null_; input; retain max; max=max(max,count(_infile_,';')); call symputx('max',max+1); cards4; case1 1;3;7 case2 2 case3 5;7;12;14 case4 1;2;4 case5 3 case6 6;8;10;12;13 case7 4;8 ;;;; run; data want; infile cards dlm=' ;' truncover; input Case $ (Q16_1-Q16_&max) ($); cards4; case1 1;3;7 case2 2 case3 5;7;12;14 case4 1;2;4 case5 3 case6 6;8;10;12;13 case7 4;8 ;;;; run;
Ksharp
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.