Friday
PeterClemmensen
Tourmaline | Level 20
Member since
01-27-2015
- 5,871 Posts
- 2,297 Likes Given
- 1,073 Solutions
- 2,198 Likes Received
This widget could not be displayed.
-
Latest posts by PeterClemmensen
Subject Views Posted 306 Friday 414 Thursday 427 Thursday 545 2 weeks ago 189 3 weeks ago 252 3 weeks ago 2372 02-19-2025 07:46 AM 391 02-16-2025 01:14 PM 457 01-16-2025 04:02 AM 496 01-15-2025 01:55 PM -
Activity Feed for PeterClemmensen
- Posted Re: Transpose Observations to Columns and add Flag on SAS Programming. Friday
- Tagged Re: Transpose Observations to Columns and add Flag on SAS Programming. Friday
- Posted Re: Transpose Observations to Columns and add Flag on SAS Programming. Thursday
- Tagged Re: Transpose Observations to Columns and add Flag on SAS Programming. Thursday
- Posted Re: Transpose Observations to Columns and add Flag on SAS Programming. Thursday
- Liked Re: Mutliple conditions applying on multiple values based on row wise for Tom. Tuesday
- Posted Re: How do i take the date value of the next row record and deduct by 1 day? on SAS Programming. 2 weeks ago
- Liked Re: Merging 2 data sets and assigning the same record_id based on common var for Ksharp. 2 weeks ago
- Got a Like for Re: format date with underscore. 3 weeks ago
- Got a Like for Re: flagging duplicate rows with complex request. 3 weeks ago
- Got a Like for Re: flagging duplicate rows with complex request. 3 weeks ago
- Posted Re: flagging duplicate rows with complex request on SAS Programming. 3 weeks ago
- Posted Re: format date with underscore on SAS Programming. 3 weeks ago
- Got a Like for Re: datetime format for dd.mm.yyyy hh:mm?. 02-24-2025 03:42 AM
- Got a Like for Re: number missing values in each obs (Numeric). 02-19-2025 10:19 AM
- Got a Like for Re: number missing values in each obs (Numeric). 02-19-2025 09:42 AM
- Got a Like for Re: number missing values in each obs (Numeric). 02-19-2025 07:56 AM
- Posted Re: number missing values in each obs (Numeric) on SAS Programming. 02-19-2025 07:46 AM
- Liked Re: Index function with % and single quote for FreelanceReinh. 02-18-2025 06:12 AM
- Liked Re: SET data set-Run speed for Patrick. 02-18-2025 03:12 AM
-
-
My Liked Posts
Subject Likes Posted 1 3 weeks ago 2 3 weeks ago 3 02-19-2025 07:46 AM 1 11-26-2019 10:13 AM 1 01-07-2025 06:07 AM
12-18-2024
03:21 AM
1 Like
Try using
options missing="";
before the Proc Print
... View more
12-18-2024
03:16 AM
How do you export to Excel?
... View more
12-06-2024
08:42 AM
1 Like
Try this
proc sql noprint;
select num_val into :num_val1 -
from have
;
quit;
%put &=num_val1.;
%put &=num_val2.;
... View more
11-29-2024
08:30 AM
2 Likes
Try this. Should perform reasonably.
Feel free to ask 🙂
data temp;
format ID formula score;
merge have
have (firstobs = 2 keep = score rename = score = s);
if score = . then do;
f = formula;
i = ID;
end;
if score then f = tranwrd(f, strip(ID), put(strip(score), 8.));
if s = . then do;
formula = compress(f);
ID = i;
score = input(resolve('%sysevalf('||formula||')'), best8.);
output;
end;
retain f i;
keep ID formula score;
format score2 8.2;
run;
Result:
ID formula score
KRI1 1/10 0.1
KRI4 (13-16)*100 -300
KRI7 (13+16)/(1-10) -3.22222
... View more
11-21-2024
08:15 AM
1 Like
Try this
data want(drop = i);
set DB;
array a {8} Age_class1 - Age_class8;
do i = 1 to dim(a);
a[i] = Index = 1;
if Index = 1 then a[Age_class] = 0;
end;
run;
... View more
11-20-2024
07:23 AM
Why is level = 2 in the 4th obs?
... View more
11-20-2024
07:19 AM
For which elements of your graph do you want to specify colors?
... View more
11-14-2024
03:24 AM
1 Like
data have;
infile cards expandtabs truncover;
input COD_SEG DT_OCORR :anydtdte. CIA_ESCOLHIDA;
format DT_OCORR yymmd7.;
cards;
37192 2021-08 1806
37192 2022-02 1806
37192 2022-03 1806
37192 2022-04 1806
37192 2022-06 1806
37192 2022-07 1806
37192 2022-08 1806
37192 2022-09 1806
37192 2022-10 2110
37192 2022-12 2110
37192 2023-01 2110
;
proc timeseries data = have out = want;
by COD_SEG;
id DT_OCORR interval = month
setmiss = prev;
var CIA_ESCOLHIDA;
format DT_OCORR yymmd7.;
run;
Result:
COD_SEG DT_OCORR CIA_ESCOLHIDA
37192 2021-08 1806
37192 2021-09 1806
37192 2021-10 1806
37192 2021-11 1806
37192 2021-12 1806
37192 2022-01 1806
37192 2022-02 1806
37192 2022-03 1806
37192 2022-04 1806
37192 2022-05 1806
37192 2022-06 1806
37192 2022-07 1806
37192 2022-08 1806
37192 2022-09 1806
37192 2022-10 2110
37192 2022-11 2110
37192 2022-12 2110
37192 2023-01 2110
... View more
10-09-2024
03:13 PM
Try replacing them for spaces or put
dlm=’09’x
in your Infile Statement.
... View more
10-09-2024
03:11 PM
I suspect you have tabs instead of spaces between your data values?
... View more
09-27-2024
02:34 PM
If your actual data is as simple as the posted sample, then why not just set querystart = min(OpenDate) and queryend = max(OpenDate) ? No need to bother with some fancy logic traversing query ID's and Parent query ID's.
... View more
09-25-2024
02:12 PM
See if this gives you what you want. I edited the have data a bit.
data HAVE_DATA(label='Patient Data');
infile datalines missover;
input Pt_ID Claim_ID:$2. (Admit_Date Discharge_Date)(:date9.);
format Admit_Date Discharge_Date date9.;
datalines;
1 A 29-Aug-21 09-Sep-21
2 B 18-Jun-21 29-Jun-21
3 C 19-Nov-17 .
4 D 08-Nov-20 22-Sep-21
4 E 20-Oct-21 18-Nov-21
4 F 19-Nov-21 .
5 G 19-Nov-21 19-Dec-21
6 H 18-Jan-21 28-Feb-21
6 I 02-Mar-21 10-Mar-21
6 J 16-Mar-21 15-May-21
6 K 21-Apr-21 22-Apr-21
6 L 05-May-21 .
6 M 05-May-21 24-Dec-21
6 N 24-Dec-21 28-Dec-21
7 O 08-Jul-20 30AAPR2021
7 P 30-Apr-21 03-May-21
7 Q 03-May-21 23-May-21
7 R 23-May-21 01-Jun-21
7 S 01-Jun-21 05-Jul-21
7 T 05-Jul-21 12-Jul-21
8 U 08-Jun-20 .
8 V 08-Jun-20 .
8 W 08-Jun-20 .
8 X 08-Jun-20 22-Oct-21
8 Y 08-Sep-21 10-Sep-21
8 Z 21-Oct-21 25-Oct-21
9 AA 13-Mar-19 .
9 AB 13-Mar-19 .
9 AC 13-Mar-19 18-May-21
9 AD 18-May-21 .
10 AE 01-Feb-21 .
;;;;
data want(drop = d);
if 0 then set HAVE_DATA;
do _N_ = 1 by 1 until (last.Pt_ID | Discharge_Date);
set HAVE_DATA;
by Pt_ID;
d = Discharge_Date;
end;
do _N_ = 1 to _N_;
set HAVE_DATA;
by Pt_ID;
if last.Pt_ID and Discharge_Date = . then Discharge_Date = intnx('year', Admit_Date, 0, 'e');
if Discharge_Date = . then Discharge_Date = d;
output;
end;
run;
Result:
Pt_ID Claim_ID Admit_Date Discharge_Date
1 A 29AUG2021 09SEP2021
2 B 18JUN2021 29JUN2021
3 C 19NOV2017 31DEC2017
4 D 08NOV2020 22SEP2021
4 E 20OCT2021 18NOV2021
4 F 19NOV2021 31DEC2021
5 G 19NOV2021 19DEC2021
6 H 18JAN2021 28FEB2021
6 I 02MAR2021 10MAR2021
6 J 16MAR2021 15MAY2021
6 K 21APR2021 22APR2021
6 L 05MAY2021 24DEC2021
6 M 05MAY2021 24DEC2021
6 N 24DEC2021 28DEC2021
7 O 08JUL2020 03MAY2021
7 P 30APR2021 03MAY2021
7 Q 03MAY2021 23MAY2021
7 R 23MAY2021 01JUN2021
7 S 01JUN2021 05JUL2021
7 T 05JUL2021 12JUL2021
8 U 08JUN2020 22OCT2021
8 V 08JUN2020 22OCT2021
8 W 08JUN2020 22OCT2021
8 X 08JUN2020 22OCT2021
8 Y 08SEP2021 10SEP2021
8 Z 21OCT2021 25OCT2021
9 AA 13MAR2019 18MAY2021
9 AB 13MAR2019 18MAY2021
9 AC 13MAR2019 18MAY2021
9 AD 18MAY2021 31DEC2021
10 AE 01FEB2021 31DEC2021
... View more
09-25-2024
07:49 AM
Show us your code 🙂
... View more
- Tags:
- s
09-24-2024
06:59 AM
2 Likes
This is a classic SAS macro issue of timing. There are two main things you need to change in your code.
Use the PUTN Function instead of the PUT Function. The PUTN Function enables you to specify a numeric format at run time. The Put Function does so at compile time, i.e. before the loop executes.
Use the Symget Function in the Data Step to retrieve the value of the macro variable during DATA step execution (not when it compiles).
I changed the input values a bit, to make the result clearer. Feel free to ask.
data df1;
a = .; b=1.235; c=1.234; output;
a = 1.234; b=.; c=1.234; output;
a = 1.234; b=1.234; c=.; output;
run;
%let _width1=5.1;
%let _width2=5.2;
%let _width3=5.3;
data want ;
set df1;
array _invars{3} a b c;
array _inval{3} $16 ;
do i = 1 to 3;
f = symget(cats('_width', i));
_inval{i}=putn(_invars{i}, f);
end;
run;
Result:
a b c _inval1 _inval2 _inval3 i f
. 1.235 1.234 . 1.24 1.234 4 5.3
1.234 . 1.234 1.2 . 1.234 4 5.3
1.234 1.234 . 1.2 1.23 . 4 5.3
... View more