BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

I would like to know how to create the result as descripted below. Thank you!

data example;

input

ind $120

tri 2.

pop_ocup 12.0

trivaria 12.0

trivaria_pc 4.0

if tri > 0 then text1 = 'The '|| ind || 'increased in ' || trivaria ||' thousand people,' || trivaria_pc ||'% in relation to the last quarter.';

Result that I want:

The population increased in 2,853 thousand people, 2.3% in relation to the last quarter.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why do you have both a SET statement and a CARDS statement?  Are you combining existing datasets or reading in-line data?


Why do you have multiple CARDS statements?  The first one will truncate the data step.  That is why the statements after it are generating errors since you cannot have an IF statement that is not part of a DATA step.


View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

catx(' ',.....)

data example;

length ind $120 trivaria trivaria_pc 8;

input ind -- trivaria_pc;

text1=catx(' ','The',ind,'inceased in',put(trivaria,comma20.)

      ,'thousand people,'

      ,cats(trivaria_pc,'%'),'in relation to the last quarter.');

put (_all_) (=/);

cards;

population 2853 2.3

;;;;

William_Kratochwill
Calcite | Level 5

Thank you,

But it is not running... Smiley Sad

this is the program:

data dados;

set

t1 t2 t3 t4 t5 t6;

trivar =  put(tri_varia_abs,commax12.0);

trivarp = Put(Tri_Varia_pc,commax12.1);

if ano = 2015 and indicadores ='a_pop_total' and tri = 'jan-fev-mar' and tri_situac = '*' and tri_varia_abs > 0 then

text1 = catx(' ','A ', indicadores, 'aumentou em ' , trivar,'mil pessoas, um aumento de ' , trivarp,'% em relação ao trimestre anterior.');

put (_all_) (=/);

cards;

if ano = 2015 and indicadores ='a_pop_total' and tri = 'jan-fev-mar' and  tri_situac = '*' and tri_varia_abs < 0 then text1 = catx(' ','A ', indicadores , 'diminuiu em ' ,  trivar,'mil pessoas, um aumento de ' , trivarp,'% em relação ao trimestre anterior.');

put (_all_) (=/);

cards;

if ano = 2015 and indicadores ='a_pop_total' and tri = 'jan-fev-mar' and  tri_situac ne '*'  then text1 = catx(' ','A ', indicadores, ' não apresentou variação estatísticamente significativa em relação ao trimestre anterior.');

put (_all_) (=/);

cards;

run;

and this is the Log:

26         if ano = 2015 and indicadores ='a_pop_total' andtri = 'jan-fev-mar' and  tri_situac = '*' and tri_varia_abs < 0 then

           __

           180

26       ! text1 = catx(' ','A ', indicadores , 'diminuiu em ' ,  trivar,'mil pessoas, um aumento de ' , trivarp,'% em relação ao

26       ! trimestre anterior.');

ERROR 180-322: Statement is not valid or it is used out of proper order.

27         put (_all_) (=/);

           ___

           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

28         cards;

           _____

           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

29         if ano = 2015 and indicadores ='a_pop_total' and tri = 'jan-fev-mar' and  tri_situac ne '*'  then text1 = catx(' ','A ',

           __

           180

29       ! indicadores, ' não apresentou variação estatísticamente significativa em relação ao trimestre anterior.');

ERROR 180-322: Statement is not valid or it is used out of proper order.

30         put (_all_) (=/);

           ___

           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

31         cards;

           _____

           180

ERROR 180-322: Statement is not valid or it is used out of proper order.

32        

33         run;

Tom
Super User Tom
Super User

Why do you have both a SET statement and a CARDS statement?  Are you combining existing datasets or reading in-line data?


Why do you have multiple CARDS statements?  The first one will truncate the data step.  That is why the statements after it are generating errors since you cannot have an IF statement that is not part of a DATA step.


William_Kratochwill
Calcite | Level 5

Thank you!

There was also another mistake in the data. But now it is running perfectly.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 903 views
  • 2 likes
  • 2 in conversation