Recently in the SAS Community Library: SAS' @AndyRavenna publishes the second of two posts that uses statistics and machine-learning objects in SAS Visual Analytics to address real-world business problems.
I have a very large dataset and I am trying to replace several numeric and character variable values (trying to null all of the values with certain variables) with either a blank or null (.). I tried the following code but got several error messages. Is this the best code or are there others? proc iml; edit mp_; read all var (Result1) where (Result1 ^= '0'); Result1 = ' '; replace all var (Result1) where (Result1 ^= '0'); run; 4 proc iml; NOTE: Writing HTML Body file: sashtml.htm NOTE: IML Ready 5 edit mp_; 6 read all var (Result1) where (Result1 ^= 0); ERROR: Operand Result1 does not have a value. statement : READ at line 6 column 1 7 Result1 = ' '; 8 replace all var (Result1) where (Result1 ^= 0); ERROR: An exception has been encountered.
... View more
I want to read reports through SAS enterprise guide, but the input will be from SAS VA. Is there a way to do it directly ? Without the need of importing each report to excel?
... View more
The code below isn't my exact code but it accurately illustrates the problem and is much simpler.
I have a macro named ABC with the argument BP_VAR. "BP" stands for "Body Part" and the values I can specify for BP_VAR are Arm, Leg and Head.
Inside the macro, there is a datastep and inside it I had code like this.
If &BP_VAR = "Arm" then do;
... some statements...
end;
And there is similar code for Leg and Head. But it wouldn't work so I found a way around it, although if you have comments on why the above didn't work then I'd be interested to hear it.
But here is the way I got around it, with a longer example to get to the meat of my question. The formats abc, def and ghi referred to below have already been defined. This code is from inside the macro.
%LET BP = "&BP_VAR";
if &BP = "Arm" then do;
...some assignment statements to create a new variable &BP.2;
format &BP.2 abc.;
end;
if &BP = "Leg" then do;
...some assignment statements to create a new variable &BP.2;
format &BP.2 def.;
end;
if &BP = "Head" then do;
...some assignment statements to create a new variable &BP.2;
format &BP.2 ghi;
end;
So as you can see, when the body part of interest is Arm, I want it to go to the Arm section of the macro and make a new variable named Arm2, makes some assignments for it, then assign a format to it. And then go on to do some other stuff that is not relevant to the current problem.
And I want to do the same when the body part of interest is Leg. And again when the body part of interest is Head.
Okay, so here is the problem. Say the body part is Arm. The if-then condition is satisfied in the first section and it creates the new variable and assigns the format abc to it. Neither of the other two if-then conditions are satisfied so it shouldn't even get into those it-then-do loops.
And yet when I run the code as listed, the format for the newly created variable Arm2 is ghi (the one in the 3rd if-then-do group). If I comment out the format assignment in the 3rd group, then the format for the new variable is def (the one in the 2nd if-then-do group).
IOW, it uses the last non-commented out format assignment statement there is even if it's inside a if-then-do group that does not get executed. I even put "put = 'gets here';" code inside the if-then-do group that I don't think is getting executed, and indeed it is not getting executed because the "gets here" message does not show up in the log. And yet somehow the format assignment in that if-then-do group does get executed.
Any idea on what's happening? Thanks in advance.
... View more
Hi,
I am getting following ERROR message while executing the below code in SAS Eguide 7.12 ; SASVersion:9.4 ; O.S : Linux64 .
Request anyof you to suggest how the below code can be executed ?
Error Message:
ERROR: The connection was reset by a peer..
Code:
%let ll1=%str(42.691560,-73.827840);
%let ll2=%str(35.805410,-78.797679);
* no changes required below this line;
filename x url "https://www.google.com/maps/dir/&ll1/&ll2/?force=lite";
filename z temp;
data _null_;
infile x recfm=f lrecl=1 end=eof;
file z recfm=f lrecl=1;
input @1 x $char1.;
put @1 x $char1.;
if eof;
call symputx('filesize',_n_);
run;
data _null_;
infile z recfm=f lrecl=&filesize. eof=done;
input @ 'miles' +(-15) @ '"' distance :comma12. text $30.;
units = scan(text,1,'"');
time = scan(text,3,'"');
file print;
put "DRIVING DISTANCE BETWEEN &ll1 AND &ll2 : "
distance units" (TIME: " time ")";
stop;
done:
file print;
put "CANNOT FIND THE DRIVING DISTANCE BETWEEN &ll1 AND &ll2 : " /
"TRY ANOTHER PAIR OF COORDINATES";
stop;
run;
filename x clear;
filename z clear;
... View more
Here is a small sample of a data set that looks like this: DATA HAVE;
INPUT ID $10. START_DT :MMDDYY10. END_DT :MMDDYY10.;
format START_DT MMDDYY10. END_DT MMDDYY10.;
datalines;
1004064609 04/01/2023 12/31/2023
1004064609 01/01/2024 12/31/3999
1004064623 04/01/2023 12/31/2023
1004064623 01/01/2024 12/31/3999
1004064703 03/06/2024 03/28/2024
1004064703 03/29/2024 12/31/3999
1004064706 04/01/2023 12/31/2023
1004064706 01/01/2024 12/31/3999
1004064724 04/01/2023 06/30/2023
1004064724 07/01/2023 11/30/2023
1004064724 12/01/2023 12/31/2023
1004064724 01/01/2024 12/31/3999
1004064726 04/01/2023 10/31/2023
1004064726 12/05/2023 12/31/2023
1004064726 01/01/2024 05/31/2024
1004064726 06/01/2024 12/31/3999
1004064727 04/01/2023 12/31/2023
1004064727 01/01/2024 12/31/3999
;
RUN; For each unique ID I want to collapse continuous date spans whenever possible. For example, for the first ID 1004064609 I would want a single record where START_DT = 04/01/2023 AND END_DT = 12/31/3999. Note that some IDs will have multiple date spans that aren't continuous and those should continue to exist as separate records. What's a solution to do this? Thank you.
... View more