Hello everybody, fairly new in the world of SAS, a curious person,say, learning in his own time. I am trying to riddle out how to make a successful POST/GET request to REST API using %macro and JSON as the primary payload and then set up a table that tracks a history of past requests and responses. Set this task to myself as it's one of the more common things people aim to do in other languages. Working with APIs. While, it takes me about 10 minutes to write such logic in JS or Python without any headaches, though I cannot string up a working logic in SAS using %macro (a term function could also be used as a synonym I guess?). A non-macro approach clicked using datalines and a hard-coded value as a prompt. I am now well aware that datalines will not budge when using macro logic so I went with put, but still not a single budge. Here's the code that I have managed to jot down so far. The API is crudcrud.com allowing up to 100 free requests. %macro api_post_request(prompt=);
%let api_url=url;
filename json_in temp;
data _null_;
file in;
put "{
""username"":""&prompt""
}"
;
run;
filename resp temp;
proc http method="POST"
url="&api_url
ct="application/json"
in=json_in
out=resp;
headers
"Content-Type"="application/json";
run;
%mend;
%api_post_request(prompt=Player1); Fierce thanks!
... View more
Hi Guys, I am trying to obtain the median value using median() function in PROC SQL as follows (SAS9.4): /* select clause with additional columns: Name Height*/
proc sql;
select Name,Sex,Height,median(Height) as Med_Height,mean(Height) as Mean_Height
from sashelp.class
group by sex
having sex="M";
quit; The results are as follows: However, when removing columns Name, Height in select clause like this: /* select clause without additional column */
proc sql;
select Sex, median(Height) as Med_Height, mean(Height) as Mean_Height
from sashelp.class
group by sex
having sex="M";
quit; The results are as follows: Comparing the two tables, the mean value of Height is still 63.91 while the median of Height changes from 64.3 to 64.15 (of course the 64.15 is the right value). Where did the first median value 64.3 come from? How did this difference (64.3 v.s. 64.15) happen? After all the mean value remains the same. I feel confused. Can anyone explain this? Thanks a lot guys. Appreciate it.
... View more
Been a long-time SAS user and wanted to try out CAS. I came across the concept of a Personal CAS Server which is like a Sandbox environment. So seems perfect for my process right now. But there is surprisingly no information to be found on how to set it up. So how do I set up a Personal CAS Server - does anyone know ?
... View more
Hi,
I need some help with writing a SAS code to handle the following scenario.
I have a data set that has multiple sites; each site has multiple patients; and each patient can have data of up to 7 days (one row represents one day). The data set has form start and save time. Data set is also setup to have no duplicates. First day data of each patient should always have the previous save and open time (both are user defined variables) as NULL. e.g., sr.1, 8, and 9 will have previous open and save time variables as NULL. And using these variables, I want to calculate the the following for each patient at a site:
number of hours a patient took between today's and yesterday's start times (i.e., from today's start to previous start) and
number of hours a patient took between today's open and yesterday's start times (i.e., from today's start to previous day save)
Sr.
PT
SITE
START_TIME
SAVE_TIME
1
001
01
4/9/2024 16:44
4/9/2024 16:46
2
001
01
4/10/2024 16:39
4/10/2024 16:40
3
001
01
4/11/2024 16:07
4/11/2024 16:08
4
001
01
4/12/2024 16:05
4/12/2024 16:06
5
001
01
4/13/2024 20:05
4/13/2024 20:06
6
001
01
4/14/2024 19:31
4/14/2024 19:52
7
001
01
4/15/2024 16:25
4/15/2024 16:25
8
002
01
4/15/2024 16:19
4/15/2024 16:20
9
003
01
4/15/2024 16:21
4/15/2024 16:22
10
002
02
4/3/2024 18:34
4/3/2024 18:41
11
002
02
4/4/2024 18:03
4/4/2024 18:09
12
002
02
4/6/2024 21:11
4/6/2024 21:14
13
002
02
4/6/2024 21:14
4/6/2024 21:16
14
002
02
4/7/2024 18:17
4/7/2024 18:20
15
002
02
4/8/2024 18:12
4/8/2024 18:14
16
002
02
4/9/2024 18:06
4/9/2024 18:08
17
004
02
4/5/2024 18:03
4/5/2024 18:10
18
004
02
4/6/2024 16:27
4/6/2024 16:32
19
004
02
4/7/2024 19:18
4/7/2024 19:22
20
004
02
4/8/2024 18:01
4/8/2024 18:07
21
004
02
4/9/2024 18:06
4/9/2024 18:16
22
004
02
4/10/2024 18:08
4/10/2024 18:10
23
004
02
4/11/2024 19:22
4/11/2024 19:26
24
005
02
4/8/2024 18:05
4/8/2024 18:07
25
005
02
4/9/2024 19:32
4/9/2024 19:34
26
005
02
4/10/2024 18:45
4/10/2024 18:47
27
005
02
4/11/2024 18:02
4/11/2024 18:04
28
005
02
4/12/2024 18:04
4/12/2024 18:07
29
005
02
4/13/2024 18:01
4/13/2024 18:03
30
005
02
4/14/2024 18:06
4/14/2024 18:08
Thanks so much in advance for all the help.
... View more