DATA Step, Macro, Functions and more

Adding new line while using catx

Reply
New Contributor
Posts: 3

Adding new line while using catx

Hi I want to add line while concatenating variables. tried a few things. Dont seem to get it done. 

The code is 

 

		DATA Y;
		SET result;
		INFORMAT R $100.;
		format R $100.;
		R = CATX(":" ,"CDE" , cde_name, "Attribute", attrib_name);
 		where total_record_count gt 10.00 or total_record_count lt -10.00;	
		RUN;
		PROC PRINT;
		title 'Y';
		RUN;


		proc sql;
		select (catx("^{newline 1}",R)) into :var separated by '^{newline 1}' from y 
		where total_record_count gt 10.00 or total_record_count lt -10.00;
		run;
Now I only get CDE:PRODUCT HIERARCHY:Attribute:PRD_HRCHY_LVL_2_CDE^{newline 1}CDE:PRODUCT 
Super User
Super User
Posts: 7,417

Re: Adding new line while using catx

Sorry, your post is not clear.  Post test data, in the form of a datastep.  Also post what you want out at the end.  Why for instance are you taking data from a datastep and putting it and formatting values into a macro variable?  Its likely your hitting a length issue, but really can't tell what you trying to do at all.  If you want some sort of list then:

data y;
  set result (where=(total_record_count gt 10.00 or total_record_count lt -10.00)) end=last;
  length r final $2000;
  retain final;
  r=catx(":","CDE",cde_name,"Attribute",attrib_name);
  final=ifc(_n_=1,r,catx(":",final,r));
  if last then call symputx('VAR',final);
run;

However that really isn't a good way to do things, you will hit line var lengths and your code will be all spaghetti.

Super User
Posts: 6,964

Re: Adding new line while using catx

Don't keep lists in macro variables. Keep them in datasets. It is much easier to create line-separated output with proc print or a data step.

 

What for would you use such a macro variable, anyway?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 2 replies
  • 109 views
  • 0 likes
  • 3 in conversation