11-28-2023
Thomas_mp
Obsidian | Level 7
Member since
06-11-2015
- 41 Posts
- 13 Likes Given
- 0 Solutions
- 0 Likes Received
-
Latest posts by Thomas_mp
Subject Views Posted 1635 11-28-2023 05:33 AM 1938 11-25-2023 06:38 AM 2613 11-14-2023 05:30 AM 2699 11-13-2023 08:28 AM 2802 11-12-2023 11:06 AM 1924 07-22-2020 02:15 PM 1924 07-22-2020 02:13 PM 1926 07-22-2020 02:10 PM 2134 07-20-2020 02:46 PM 3065 07-11-2020 11:31 AM -
Activity Feed for Thomas_mp
- Posted Re: Create a new variable that adds the character “_" in front of the values of an existing var on New SAS User. 11-28-2023 05:33 AM
- Liked Re: Create a new variable that adds the character “_" in front of the values of an existing var for Tom. 11-28-2023 05:33 AM
- Liked Re: Create a new variable that adds the character “_" in front of the values of an existing var for Astounding. 11-28-2023 05:32 AM
- Posted Create a new variable that adds the character “_" in front of the values of an existing variable on New SAS User. 11-25-2023 06:38 AM
- Posted Re: Merging several observations with different dates on SAS Procedures. 11-14-2023 05:30 AM
- Posted Re: Merging several observations with different dates on SAS Procedures. 11-13-2023 08:28 AM
- Posted Merging several observations with different dates on SAS Procedures. 11-12-2023 11:06 AM
- Posted Re: Publish/create descriptive tables on ODS and Base Reporting. 07-22-2020 02:15 PM
- Posted Re: Publish/create descriptive tables on ODS and Base Reporting. 07-22-2020 02:13 PM
- Posted Re: Publish/create descriptive tables on ODS and Base Reporting. 07-22-2020 02:10 PM
- Liked Re: Publish/create descriptive tables for PaigeMiller. 07-22-2020 02:08 PM
- Liked Re: Publish/create descriptive tables for Reeza. 07-22-2020 11:20 AM
- Posted Publish/create descriptive tables on ODS and Base Reporting. 07-20-2020 02:46 PM
- Posted Re: Compute the number of observations and sum in a moving window on SAS Data Management. 07-11-2020 11:31 AM
- Liked Re: Compute the number of observations and sum in a moving window for Kurt_Bremser. 07-11-2020 11:26 AM
- Posted Re: Find out the how much a person spent in the last 100 days, on SAS Procedures. 07-11-2020 11:24 AM
- Liked Re: Find out the how much a person spent in the last 100 days, for Ksharp. 07-11-2020 11:24 AM
- Posted Re: Compute the number of observations and sum in a moving window on SAS Data Management. 07-10-2020 04:51 PM
- Posted Compute the number of observations and sum in a moving window on SAS Data Management. 07-10-2020 04:20 PM
- Posted Compute the number of observations and sum in a moving window on SAS Data Management. 07-10-2020 04:19 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 1 1 2 1
11-28-2023
05:33 AM
Thank you Tom !!
... View more
11-25-2023
06:38 AM
Hello,
I need to create a new variable that adds the character “_" in front of the value of an existing variable. I find this easy to do in Excel, but I cannot do it in SAS.
An example:
This is what I have
data have ; input date va vb $;
cards ;
20000630 6.1207 to
20000929 6.1158 ri
20001229 5.7898 to
20010330 4.9815 co
;
run;
I need to generate new variable _va that adds _ to the values of the existing variable va.
So, I would like to have this:
data want
Date va _va vb
20000630 6.1207 _6.1207 to
20000929 6.1158 _3.1158 ri
20001229 5.7898 _5.7898 to
20010330 4.9815 _4.9815 co
Thank you for your help
... View more
11-14-2023
05:30 AM
Thank you Paul, This works.
One more question taht you very likely know how to answer.
Your input code to read the SAS dataset is:
input date_all :mmddyy. (date_c1 C1 date_c2 C2 date_c3 C3 date_c4 C4 ) (:mmddyy10. :32.);
You had 3 variables (C1,C2, C3), I just added one more to see if I could run your code with one more variable, and I did. But I need to add 470 more variables C1., C2,......C470 and the corresponding dates date_c1 ... date_c470
Do you know how to write a simple input statement to read the 470 variables and dates ?
Thank you again.
Tomas
... View more
11-13-2023
08:28 AM
Hello Tom,
Thank you for trying to help.
You write : "So looking at the data you posted it looks like you have this data"
However, this is not what I have, but what I would need to have.
Attached here is what I have. You can get this running the sort program attached to the post with my original question.
Thank you again
Best,
Tomas
... View more
11-12-2023
11:06 AM
Hello,
I have hundreds of subjects (variables) that have observations for some dates but not for other dates. I need to have the variables with observations for all the dates, with missing values for the dates with missing information.
The best a way to explain this is with one example. Below you will see cards for the data set "have" . The first column has all the dates that need to appear in the final desired outcome. The second column only has the dates with observations for variable C1; The next column (C1) has the values for this variable. The other columns have similar information for the variables C2 and C3.
Here is the information:
data have; input date_all :mmddyy10. date_c1 :mmddyy10. C1 date_c2 :mmddyy10. C2 date_c3 :mmddyy10. C3 ; format date_all mmddyy10. date_c1 mmddyy10. date_c2 mmddyy10. date_c3 mmddyy10. ; cards;
1/3/2000 1/3/2000 0.5 1/8/2000 0.04 1/5/2000 . 1/4/2000 1/4/2000 0.6 1/9/2000 0.07 1/6/2000 . 1/5/2000 1/5/2000 0.7 . . 1/7/2000 . 1/6/2000 1/6/2000 . . . 1/8/2000 . 1/7/2000 1/7/2000 . . . 1/9/2000 . 1/8/2000 1/8/2000 . . . 1/10/2000 0.28 1/9/2000 1/9/2000 . . . 1/11/2000 0.15 1/10/2000 1/10/2000 . . . 1/12/2000 . 1/11/2000 1/11/2000 . . . 1/13/2000 . 1/12/2000 1/12/2000 . . . 1/14/2000 0.28 1/13/2000 1/13/2000 . . . . . 1/14/2000 1/14/2000 . . . . .
;run;
proc print; run ;
As you can see, I only have missing observations for the variables C1,C2 and C3 in some dates. I need observations for the 3 variables for all the dates, with missing values where the observation is missing to conduct the analysis.
Please, in the attached message you can see the final desired outcome (and the initial observations in this message) .
I would appreciate your help. with this.
Tomas
... View more
07-22-2020
02:15 PM
Thank you Ballard. Your code helps to read the output, but now I will continue using STATA; i find it easier and more"flexible". But thank you for your time, Tomas
... View more
07-22-2020
02:13 PM
Thank you again Reeza, His is the 3 occasion you take time to answer my questions. This works, but for now I will continue using STATA; it produces the output in a way I can easily manipulate for papers in my discipline (finances). But thank you for your time, Tomas
... View more
07-22-2020
02:10 PM
Thank you Paige.
I need time to do this in SAS. For now I will continue using STATA.
But thank you for your time,
Tomas
... View more
07-20-2020
02:46 PM
Good morning,
I have been using SAS 9.4 for some simple analysis, but I use STATA to produce descriptive statistics tables ready to insert in a MS Word document (for instance). In STATA esttab creates rtf (text document). In SAS, I have spent the morning searching online for a “simple” similar way, but I got overwhelmed by the large amount of information and the relatively complex and specific code. This is the reason I am contacting you for help.
Is there a simple way in SAS to produce a table with summary statistics means/nedians/max/sdvt.... ? Perhaps, if I have a template I can modify it.
An example:
data k;
input X $ d y z;
informat d mmddyy8. ;
cards ;
a 01/01/96 5.1 110.500
a 10/27/96 2.3 109.500
a 12/16/96 8.1 110.200
a 01/05/97 9.6 99.000
a 01/11/97 1.6 .
b 02/03/97 6.2 100.269
b 03/25/97 5.8 50.560
b 11/15/98 2.6 42.250
b 01/14/99 4.9 12.160
b 01/29/99 3.7 .
b 03/10/99 4.6 800.000
b 03/10/99 2.3 200.100
c 03/16/99 9.6 5.690
;run;
proc sort data= k; by x; run;
proc univariate data=k noprint ;
var y z;
by x;
output out= tabl
mean = mean_y mean_z
median = median_y median_z
n= n_y n_z
max =max_y max_z
min= min_y min_z
std = st_y st_z;
;run;
proc print data = tabl; run;
The question is: is there a way of using this information to produce a table similar to this:
For individual a
Vble
Obs
Mean
(median)
Max
(min)
std
Y
5
5.340
(5.100)
9.600
(1.600)
3.502
Z
4
107.300
(109.850)
110.500
(99.000)
5.549
For individual b
Obs
Mean
(median)
Max
(min)
std
Y
5
3.860
(3.700)
76.268
(46.405)
1.491
Z
4
107.300
(5.100)
110.500
(99.000)
84.187
For ind c
Obs
Mean
(median)
Max
(min)
std
Y
1
9.600
(9.600)
9.600
(9.600)
Z
1
5.690
(5.690)
5.690
(5.690)
Thank you for your help,
Tomas
... View more
07-11-2020
11:31 AM
Good morning Kurt,
Thank you for your time. Your program does what I was expecting.
However, the program below (sent by other member of the community) corrects my own mistakes. This is: for the same individual/date (last two observations for individual b) we should have the same values for time and sum.
Thank you again,
Have a good weekend
Tomas
data k;
input X $ d y ;
informat d mmddyy8. ;
cards ;
a 01/01/96 5.1
a 10/27/96 2.3
a 12/16/96 8.1
a 01/05/97 9.6
a 01/11/97 1.6
b 02/03/97 6.2
b 03/25/97 5.8
b 11/15/98 2.6
b 01/14/99 4.9
b 01/29/99 3.7
b 03/10/99 4.6
b 03/10/99 2.3
c 03/16/99 9.6
;
proc sql;
create table want as
select *,
(select count(*) from k where x=a.x and d between a.d-100 and a.d) as times,
(select sum(y) from k where x=a.x and d between a.d-100 and a.d) as sum
from k as a;
quit;
... View more
07-11-2020
11:24 AM
Thank you , I appreciate your help. It is simple and it works perfectly. Thank you again for your time. Tomas
... View more
07-10-2020
04:51 PM
Hi Reeza, it is the same question but with a few more explanations .. and perhaps it does not belong to the procedures, and fits better in data management part of SAS?
... View more
07-10-2020
04:20 PM
Good morning, I have observations of thousands of individuals (variable X for individuals a, b, c, d.. ) overtime (d) and the money each individual spent on that date (Y). The data are sorted by X and d data k; input X $ d y ; informat d mmddyy8. ; cards ; a 01/01/96 5.1 a 10/27/96 2.3 a 12/16/96 8.1 a 01/05/97 9.6 a 01/11/97 1.6 b 02/03/97 6.2 b 03/25/97 5.8 b 11/15/98 2.6 b 01/14/99 4.9 b 01/29/99 3.7 b 03/10/99 4.6 b 03/10/99 2.3 c 03/16/99 9.6 ; run; I am trying to resolve two questions: How many times one individual spent money in a period of 100 days? (this is the variable “times” in the solution below) How much money has she/he spent in a the last 100 days? (this is “sum” in the solutions below. So the question is to find out “times” and “sum”: the times an individual appears in the data base in the last 100 days, and the money spent in the last by this individual in the last 100 days. For instance, for individual b: She appears on 2/3/1997 for the first time, so times = 1; sum = 6.2 She appears again on 3/25/1997 , or 50 days later, so times = 2 (2/3/1997 and 3/25/1997) and sum is = 12 (5.8+6.2). She appears again on 11/15/1998, or 300 days later, so times = 1 (because 300 > 100)) and sum is = 2.6. She appears again on 1/14/1999, or 60 days later, so times = 2 and sum is = 2.6 + 4.9 = 7.5. She appears again on 1/29/1999, or 15 days later, so times = 3 (3 times in 100 days, on 11/15/1998, on 1/14/1999 and on 1/29/1999. Sum is the value of Y on these 3 dates (3.7+4.9+2.6) She appears again on 3/10/1999, or 40 days later, so times = 3 (3 times in 100 days, on 1/14/1999 on 1/29/1999 and on 3/10/1999. Sum is the value of Y on these 3 dates (3.7+4.9+2.3) I did the complete solution in excel, below (and in the attached file). Diff is the number of days between two dates (I did this to get to the solution in excel; it may not be necessary). This difference is -999 when we change to a different individual. In this case the solution is: x d y diff times sum a 1/1/1996 5.1 -999 1 5.1 a 10/27/1996 2.3 300 1 2.3 a 12/16/1996 8.1 50 1 10.4 a 1/5/1997 9.6 20 2 20 a 1/11/1997 1.6 6 3 21.6 b 2/3/1997 6.2 -999 1 6.2 b 3/25/1997 5.8 50 2 12 b 11/15/1998 2.6 600 1 2.6 b 1/14/1999 4.9 60 1 7.5 b 1/29/1999 3.7 15 2 11.2 b 3/10/1999 4.6 40 3 8.3 b 3/10/1999 2.3 0 4 10.6 c 3/16/1999 9.6 -999 1 9.6 Thank you for your help, Tomas
... View more
07-10-2020
03:37 PM
Sorry Kurt: data k; input X $ d y ; informat d mmddyy8. ; cards ; a 01/01/96 5.1 a 10/27/96 2.3 a 12/16/96 8.1 a 01/05/97 9.6 a 01/11/97 1.6 b 02/03/97 6.2 b 03/25/97 5.8 b 11/15/98 2.6 b 01/14/99 4.9 b 01/29/99 3.7 b 03/10/99 4.6 b 03/10/99 2.3 c 03/16/99 9.6
... View more