08-03-2016
alisondu77
Obsidian | Level 7
Member since
03-30-2016
- 15 Posts
- 5 Likes Given
- 0 Solutions
- 2 Likes Received
-
Latest posts by alisondu77
Subject Views Posted 2181 08-02-2016 02:58 AM 2182 08-02-2016 02:56 AM 2219 08-01-2016 07:26 AM 35855 05-30-2016 03:09 AM 35857 05-30-2016 03:06 AM 35902 05-25-2016 08:06 AM 2108 04-25-2016 07:03 AM 2130 04-25-2016 05:51 AM 2141 04-25-2016 05:31 AM 2008 04-01-2016 09:36 AM -
Activity Feed for alisondu77
- Posted Re: scan in a proc data on SAS Procedures. 08-02-2016 02:58 AM
- Posted Re: scan in a proc data on SAS Procedures. 08-02-2016 02:56 AM
- Liked Re: scan in a proc data for RW9. 08-02-2016 02:55 AM
- Liked Re: scan in a proc data for Reeza. 08-02-2016 02:55 AM
- Posted scan in a proc data on SAS Procedures. 08-01-2016 07:26 AM
- Posted Re: Check if a table exist in PROC SQL on SAS Procedures. 05-30-2016 03:09 AM
- Posted Re: Check if a table exist in PROC SQL on SAS Procedures. 05-30-2016 03:06 AM
- Posted Check if a table exist in PROC SQL on SAS Procedures. 05-25-2016 08:06 AM
- Liked Re: Comparing a date variable to a year, to calculate how many date variables are in this year for Loko. 04-26-2016 04:04 AM
- Liked Re: Comparing a date variable to a year, to calculate how many date variables are in this year for RW9. 04-26-2016 04:03 AM
- Posted Re: Comparing a date variable to a year, to calculate how many date variables are in this year on SAS Procedures. 04-25-2016 07:03 AM
- Posted Re: Comparing a date variable to a year, to calculate how many date variables are in this year on SAS Procedures. 04-25-2016 05:51 AM
- Posted Comparing a date variable to a year, to calculate how many date variables are in this year on SAS Procedures. 04-25-2016 05:31 AM
- Posted Re: Combination of sets on SAS Data Management. 04-01-2016 09:36 AM
- Got a Like for Re: Combination of sets. 04-01-2016 09:35 AM
- Posted Re: Combination of sets on SAS Data Management. 04-01-2016 09:24 AM
- Posted Combination of sets on SAS Data Management. 04-01-2016 09:04 AM
- Posted Re: Utilisation de macro variables pour INTNX : ne me retourne rien on SAS Procedures. 03-31-2016 08:11 AM
- Liked Re: Utilisation de macro variables pour INTNX : ne me retourne rien for RW9. 03-31-2016 08:05 AM
- Posted Re: Utilisation de macro variables pour INTNX : ne me retourne rien on SAS Procedures. 03-31-2016 03:02 AM
-
Posts I Liked
Subject Likes Author Latest Post 6 1 1 1 1 -
My Liked Posts
Subject Likes Posted 2 04-01-2016 09:24 AM
08-02-2016
02:58 AM
Yes, thank you it works too. I didn't know that we have to put " " around the macro-variable in a scan. Thank you ! Have a nice day 😉 Alison
... View more
08-02-2016
02:56 AM
Thank you so much for your answer and your advice. It works very well 😉 Best regards. Alison
... View more
08-01-2016
07:26 AM
Hello everyone, From a macro variable declared by a user (year), i want to have the first day of all the month of the period. For example if someone put : %let year = 2014 2015; I want to have "01jan2014", "01feb2014", "01mar2014" ... "01nov2015" "01dec2015". I want to have this date save in different macro variable (date_1, date_2, date_3 ..., date_23, date_24). So I have made a code, which works by half. I succeed in having the "01mmm" but not the YYYY. %global year;
%let year = 2014 2015 ; /* the user choose the year*/
%global nb_year;
%let nb_year=%sysfunc(countw(&year.));
%put &nb_year. ; /*count the number of years*/
/* dates are saving in date_k (date_1 for "01jan2014", date_2 for '01feb2014"d ...) */
data _null_;
k=0;
ATTRIB month LENGTH=$5 ;
do i=1 to (&nb_year.);
year2 = scan(&year.,i,' ') ; /*this step doesn't work*/
do j=1 to 12 ;
if j=1 then month= "01jan";
if j=2 then month="01feb";
if j=3 then month="01mar";
if j=4 then month="01apr";
if j=5 then month="01may";
if j=6 then month="01jun";
if j=7 then month="01jul";
if j=8 then month="01aug";
if j=9 then month="01sep";
if j=10 then month="01oct";
if j=11 then month="01nov";
if j=12 then month="01dec" ;
k=k+1;
ym=(month)||(year2);
call symput(cats('date_',k),ym);
end;
end ;
run ;
%put &date_20.; So everything works except the lign where i declare "year2". Can somenone help me to solve my problem ? Sorry for my poor english ... Best regards, Alison
... View more
05-30-2016
03:09 AM
Thanks you for your answer ! In my case it doesn't fit really well because of my "select" which is different given the table, but i'm going to use it in an other work. Thanks you very much ! Have a nice day ! Alison
... View more
05-30-2016
03:06 AM
Thanks you for your quick answer ! That works very well, it's exactly what i want, even if it's " a mess" like you said ! My team wanted an automatization of a script, which work even if table1 or table2 doesn't exist. Thanks you ! Have a nice day, Alison
... View more
05-25-2016
08:06 AM
Hello everyone, In a proc sql, I would like to test the existence of a table. This is my code (which doesn't work and i have no idea how to do it) : proc sql ;
create table union as
if exist(table1) then (
select id1, . as id2, number
from table1
)
union
if exist(table2) then (
select '' as id1, id2, number
from table2
)
; quit ; I have seen on the internet something like this, but i don't know how to put it in my case : %macro test(name);
%if %sysfunc(exist(&name)) %then
/* union of the 2 tables */
;
%mend test; Thank you in advance, and sorry for my poor english 😕 ! Have a nice afternoon ! Alison
... View more
04-25-2016
07:03 AM
You have surely right, I didn't manage very well "counting" procedures that's why, unfornunately, I make complicate things for "simple" things. Sorry I am still student and didn't practice so much on data procedures... 😕 I'm trying to learn by myself 😕 Thank you all for your advice and taking time for me ! Alison
... View more
04-25-2016
05:51 AM
Thank you ! So, I should do something like this : %macro test() ;
%let date_start = "01jan2015"d;
%let nb_month_2014=0;
%let nb_month_2015=0;
%do i=0 %to 11 ;
%let dt=%sysfunc(intnx("month",&date_start.,&i.,'same'));
%if put(%sysfunc(year(&dt.),z4.))=2014 %then %let nb_month_2014 = %eval(&nb_month_2014 + 1) ;
%if put(%sysfunc(year(&dt.),z4.))=2015 %then %let nb_month_2015 = %eval(&nb_month_2015 + 1) ;
%end;
%mend ;
%test()
%put nb_month_2014 = &nb_month_2014. ;
%put nb_month_2015 = &nb_month_2015. ; I don't manage my errors, I am a beginner in macro ... Can you help me to find what's wrong in my script ? Thank you in advance ! Alison
... View more
04-25-2016
05:31 AM
Hello everyone, I have a little problem in my script SAS. I have a starting date (01jan2015), and I add to this date one month eleven times (01jan2015, 01feb2015, ..., 01dec2015). There is no problem for that, but after I would like to count how many dates are in 2015 or 2014, and i don't succeed... I just have "1" in output for nb_month_2014 and nb_month_2015, which is wrong. I should have : nb_month_2014= 0 and nb_month_2015=12. %let date_start = "01jan2015"d;
%let nb_month_2014=0;
%let nb_month_2015=0;
data _null_;
do i=0 to 11 ;
dt=intnx("month",&date_start.,i,'same');
if (put(year(dt),z4.)=2014) then %let nb_month_2014 = %eval(&nb_month_2014 + 1) ;
if (put(year(dt),z4.)=2015) then %let nb_month_2015 = %eval(&nb_month_2015 + 1) ;
end;
run;
%put nb_month_2014 = &nb_month_2014. ;
%put nb_month_2015 = &nb_month_2015. ; Thank you for helping me ! and sorry for my poor english ! Alison
... View more
04-01-2016
09:36 AM
That's exactly what I want ! I didn't know the function "COALESC" ! Thank you so much for your quick and efficient answer ! And to reply to your question, I agree with you but it's not my data and I can not change the dataset. Sets are really to big. Thank you again !
... View more
04-01-2016
09:24 AM
2 Likes
Oh sorry, it was just an exemple what i post here. But i have translate the picture into code : data lib.montant1206;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4 9.2 mt_5 9.2 mt_6 9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 1 . . . . . . . .
a13 . 2 . . . . . . .
a14 . . . . 4 . . . .
a15 . . . . . . . . .
a16 3 . . . . . . . .
;
data lib.montant1207;
format id $3. mt_1 9.2 mt_2 9.2 mt_3 9.2 mt_4 9.2 mt_5 9.2 mt_6 9.2 mt7 9.2 mt_8 9.2 mt_9 9.2;
input id mt_1 mt_2 mt_3 mt_4 mt_5 mt_6 mt7 mt_8 mt_9;
cards;
a12 . 2 . . . . . . .
a13 . . 3 . . . . . .
a14 . . . . . 6 . . .
a15 7 . . . . . . . .
a16 . 10 . . . . . . .
; Thank you !
... View more
04-01-2016
09:04 AM
Hello everyone, I have a solution to my problem, but I would like something more efficient and quicker. I think you can understand on the picture what I want. I would like to associate two sets (blue and green) or more, to do the red one (it's simply to combination of the 2 sets with null data when there is no number). So this is my script SAS : /* creation of the set where i save the result */
proc sql ;
create table lib.montant_result as (
select id_dossier, 0 as montant_1, 0 as montant_2,0 as montant_3, 0 as montant_4,
0 as montant_5, 0 as montant_6,0 as montant_7, 0 as montant_8, 0 as montant_9
from lib.clients ;
quit ;
%Macro evolution_montant(YYMM) ;
/* creation of the blue and green sets */
proc sql ;
create table lib.montant_month as (
select id_dossier,
case when intck("month",date,"01jul2013") = 1 then montant end as montant_1,
case when intck("month",date,"01jul2013") = 2 then montant end as montant_2,
case when intck("month",date,"01jul2013") = 3 then montant end as montant_3,
case when intck("month",date,"01jul2013") = 4 then montant end as montant_4,
case when intck("month",date,"01jul2013") = 5 then montant end as montant_5,
case when intck("month",date,"01jul2013") = 6 then montant end as montant_6,
case when intck("month",date,"01jul2013") = 7 then montant end as montant_7,
case when intck("month",date,"01jul2013") = 8 then montant end as montant_8,
case when intck("month",date,"01jul2013") = 9 then montant end as montant_9,
FROM lib.clients clients
inner join lib.montant&YYMM. mont on mont.id_dossier = clients.id_dossier );
quit ;
/*creation and update of the red set (result) */
proc sql ;
UPDATE lib.montant_result a
SET montant_1 = sum(a.montant_1 ,(SELECT b.montant_1 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )),
montant_2 = sum(a.montant_2 ,(SELECT b.montant_2 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )) ,
montant_3 = sum(a.montant_3 ,(SELECT b.montant_3 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )) ,
montant_4 = sum(a.montant_4 ,(SELECT b.montant_4 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )),
montant_5 = sum(a.montant_5 ,(SELECT b.montant_5 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )),
montant_6 = sum(a.montant_6 ,(SELECT b.montant_6 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )),
montant_7 = sum(a.montant_7 ,(SELECT b.montant_7 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )),
montant_8 = sum(a.montant_8 ,(SELECT b.montant_8 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier )),
montant_9 = sum(a.montant_9 ,(SELECT b.montant_9 FROM alison.montant_month b WHERE a.id_dossier = b.id_dossier ))
;
quit ;
%mend evolution_montant; Thank you in advance. And sorry for my poor english ! Have a good weekend !
... View more
03-31-2016
08:11 AM
Ohhhhh thank you so much ! It works very well ! Thank you, I was disappointed not to find the solution ! I made a little transformation of the solution to fit correctly on my datasets. And you were right about the 'restriction', but it's because i simplify the code and so, it seems weird and like there are no restrictions 🙂 So this is the final version (with comment in French sorry 🙂 😞 %global date_debut_ouverture nbmois;
%let date_debut_ouverture = "01sep2013"d;
%let nbmois = 24 ;
/*MACRO pour calculer date_debut_ouverture + i mois*/
data _null_;
do i=1 to &nbmois;
dt=intnx("month",&date_debut_ouverture.,i,'same'); /* date_debut_ouverture + i mois */
dt_bis = put(dt,date9.) ; /* dt sous format 01oct2013*/
ym=substr(put(year(dt),z4.),3)||put(month(dt),z2.); /* ym = 1310 (format 'YYMM') */
call symput(cats('date_table_',i),ym); /* enregistrement dans date_table_i = ym */
call symput(cats('date_',i),dt_bis); /* enregistrement dans date__i = dt */
end;
run;
/*on lit les tables WORK.A_YYMM etc. */
%Macro fonction_table(YYMM);
proc sql ;
create table work.sortie as select *
FROM work.A_&YYMM ; /* lecture de la table : work.A_1310 */
quit ;
%Mend fonction_table;
%fonction_table(&date_table_1);
Thank you again !!! Super answer !!! 🙂 Have a good day RW9 🙂
... View more
03-31-2016
03:02 AM
Hello everyone, Sorry my English is poor but thank you for your complete and quick answers. I can’t change my dataset, I have millions of data in each sets. So I have to use the name of the sets “work.A_YYMM” to do my work. And it’s forbidden to me to change the datasets 😕 sorry. I will try to explain you what I want to do : I save “01sept2013” in a variable : date_debut_ouverture : OK it’s work Then I would like to calculate for i from 1 to 24 : date_debut_ouverture + I * month (save in the variable date_i). That’s to say I would like : Date_1 = ‘01oct2013 Date_2 = ’01nov2013’ ... Date_24 = ‘01aug2015’. To do this I choose the function : intnx --> (%let date_&i = %SYSFUNC(intnx("month", &date_debut_ouverture, &i, 'same'),date9.); But when I want to see the result, I have ‘ ‘ (so nothing). And I didn’t understand why and I have no errors in my log. Then I would like to use the variable date_i, to transform it in a number which represent YYMM (save in the variable date_table_i), so for example : Date_table_1 = 1310 Date_table_2 = 1311 … Date_table_4 = 1508 I didn’t go so far in this point, because of the previous step (2) that didn’t work. What I want to do with this, is to use date_table_i to call sets which looks like “A_YYMM”, and to use date_i for some sections where in some others proc sql like (where date=&date_i). Thank you again, and have a good day ! Alison
... View more
03-30-2016
08:57 AM
Bonjour, Je rencontre actuellement un problème sous SAS et j'avoue que cela fait un bout de temps que je n'en ai pas fait... Mon problème est le suivant : 1) je souhaite sauvegarder dans date_debut_douverture la date "01sep2013"d : OK cela fonctionne 2) je souhaite calculer date_i = date_debut_douverture + i mois (via la fonction intnx : PB cela me retourne " " et non pas "01oct2013"d, "01nov2013"d etc, je n'ai pas d'avertissement sous SAS 3) je souhaiterais ensuite calculer date_table_i pour avoir respectivement un NOMBRE correspondant à YYMM : 1310, 1311, 1312, 1401 etc : PB ça ne fonctionne pas vu que l'étape 2 ne fonctionne pas... Cette variable me permettra ensuite de faire appel à un table de type WORK.A_1310, WORK.A_1311... J'ai absolument besoin des deux variables date_i et date_table_i (date_i me servira pour d'autres fonctions que je n'ai pas mise dans mon code). Voici mon script : %global date_debut_ouverture ;
%let date_debut_ouverture = "01sep2013"d;
/*MACRO pour calculer date_debut_ouverture + i mois*/
%macro calcul_date(nbmois);
%do i=1 %to &nbmois;
%global date_&i date_table_&i ;
%let date_&i = %SYSFUNC(intnx("month", &date_debut_ouverture, &i, 'same'),date9.);
%let date_table_&i = %SYSFUNC(putn(&date_&i.,yymmn4.),yymmn4.); /*je pense qu'il manque tout de même l'étape où il y a la transformation de la date en chiffre */
%end;
%mend calcul_date;
%calcul_date(24);
/*on lit les tables WORK.A_YYMM etc. */
%Macro fonction_table(YYMM);
proc sql ;
create table work.sortie as select *
FROM work.A_&YYMM ;
quit ;
%Mend fonction_table;
%fonction_table(&date_table_1); Je vous remercie par avance de votre aide, et vous souhaite une bonne journée 🙂 Alison
... View more