Hi! In my data step:
/*Setting Length for redcap_event_name in Databse and Inputting QI Variable Values*/
%let RR=rr100d;
%let RT=rt190;
data three;
length id $ 6;
length record_id $ 30;
length redcap_event_name $ 30;
set two;
qi104="Date of scan acquisition on the RT Form (Item 90: &RT) is after the date the radiology review is completed on the RR Form (Item d: &RR).
The date of scan acquisition should be before the date of radiology review. Please review forms for the accuracy of the dates and or return this query with your comments";
run;
I am trying to create a variable, qi104, that pulls in the value of the variables rt190 and rr100d in the quote for each of the observations. Each observation has unique values for rt190 and rr100d. However, it seems that my macro syntax just pulls in the text "rt190" or "rr100d" rather than the value of those respective variables for the quoted string represented by variable qi104. What am I doing wrong? Any input regarding this would be much appreciated. Thanks so much!
No need for macrovariables here:
data three;
length id $ 6;
length record_id $ 30;
length redcap_event_name $ 30;
set two;
qi104=cats(
"Date of scan acquisition on the RT Form (Item 90: "
,rr100d
,") is after the date the radiology review is completed on the RR Form (Item d: "
,rt190
,"). The date of scan acquisition should be before the date of radiology review. Please review forms for the accuracy of the dates and or return this query with your comments"
);
run;
A word of explanation.
Your original code won't do what you expect because macrovariables values were "rr100d" and "rt190" and those values were inserted into the text string. Macrovariables work as a "code text" replacement and a text like: "blablabal... &RR ...blablabla" is transformed by macroprocessor to: "blablabal... rr100d ...blablabla".
Bart
[EDIT:]
Read the documetation:
1) https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1jgr545j3yz29n1uic9qlvlrzo4.htm
2) https://documentation.sas.com/doc/en/pgmsascdc/v_049/sqlproc/p0lsf4btafkw9mn1md4c69kkfwbl.htm
or watch the tutorial:
3) https://www.youtube.com/watch?v=ODq6V69IX2Y
Thanks for your help @yabwon ! Does the cats function not seem to agree with particular characters (e.g. parentheses or colons)? For some reason, when I try to run a similar code, qi104 ends up being blank, even though there is no error code saying that it's uninitiated.
What "similar code"? Show us the code. Show us the unexpected output. Show us a portion of the data for q104.
@PaigeMiller already wrote what you should do to get our help...
Bart
P.S. the CATS() works like this:
result = cats(string1, string2, ..., stringN);
Hi @yabwon , @ballardw , and @PaigeMiller ; thanks for your help. @yabwon , your syntax was the one that I did use. My code is as follows:
data three;
length id $ 6;
length record_id $ 30;
length redcap_event_name $ 30;
set two;
where rt190 > rr100d and rt190 ne . and rr100d ne .;
rtdate=put(rt190, MMDDYY10.);
rrdate=put(rr100d, MMDDYY10.);
number=_n_;
id=put(number, z6.);
event_id=48807;
record_id_complete=2;
if rr100d <> . then do;
form_letter_1="RR";
page="rr_ct_scan_acquisition_form";
end;
if rt190 <> . then do;
form_letter_2="RT";
page="rt_ct_scan_acquisition_form";
end;
qi100a=upcase(redcap_data_access_group);
qi100c="rt_after_rr";
qi100b=cats(qi100c, '_', id);
record_id=qi100b;
qi100d='02APR2024'd;
qi100e="V01";
qi100q="AXA010";
qi100r=1;
qi101=1;
qi101_s1a=pi100b;
qi101_s1b=pi100c;
qi102___a=1;
qi103___b=1;
qi104=cats('Date of scan acquisition on the RT Form (Item 90: ', rtdate, ')',
'is after the date the radiology review is completed on the RR Form (Item d:', rrdate, '). ', 'The date of scan acquisition should be before the date of radiology review. Please review forms for the accuracy of the dates and or return this query with your comments.');
run;
proc print data=three;
var qi104;
run;
The relevant log is as follows:
WARNING: In a call to the CATS function, the buffer allocated for the result was not long enough to
contain the concatenation of all the arguments. The correct result would contain 317
characters, but the actual result might either be truncated to 200 character(s) or be
completely blank, depending on the calling environment. The following note indicates the
left-most argument that caused truncation.
NOTE: Argument 7 to function CATS('Date of scan'[12 of 50 characters shown],'04/22/2023',')','is
after the'[12 of 75 characters shown],'04/22/1996','). ','The date of '[12 of 170 characters
shown]) at line 2877 column 7 is invalid.
Any thoughts?
If you don't define you variables, like qi104, then SAS is forced to GUESS how you intended them to be defined.
Looks it guessed to make it too short for the strings you are trying to store in it.
You seem to know how to define variables since you are doing it for id, record_id and redcap_event_name.
Hi @Tom , many thanks for your help! It seems to be a length issue for the concatenated variable. Would you recommend that I pre-define the length of the variable where I am trying to concatenate various strings of text? Thanks again for your help!
@JackZ295 wrote:
Hi @Tom , many thanks for your help! It seems to be a length issue for the concatenated variable. Would you recommend that I pre-define the length of the variable where I am trying to concatenate various strings of text? Thanks again for your help!
Yes. You should be able to define a length that is longer than any possible value your code will try to store in it.
In general you should define your character variables instead of letting SAS guess what length they need. When it guesses it will usually guess a length of either 8 or 200 bytes when there is no other clear basis for it to choose something else. In your example it is probably choosing $200 and that is ending up being too short.
You need to defile proper length for expected value of
qi104
I guess something like:
length qi104 $ 500;
before line with CATS() function should help.
B.
LOG.
Show the LOG.
"Similar" is not the same as Identical.
Data might be needed but the CATS function is not going to do much of anything except remove leading and trailing spaces when values are combined. A result of blank means that you gave the function blank input or tried to assign a character value to a numeric variable that couldn't be converted to numeric.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: