BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

Let's say that in vector parameter we have 5 arguments:

current month+previous month+last DEC+same month previous year+last month previous quarter

 

Sometimes some arguments are same.

for example:

current month=1807

previous month=1806

last DEC=1712

same month previous year=1707

last month previous quarter=1806

vector=1807+1806+1712+1707+1806;

 

How can I tell sas that in case that there are identical arguments in &vector parameter to  leave only one of them.

so I want that    vector=1807+1806+1712+1707;;

 

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Store data in a dataset, then use Base SAS datasteps and procedures to manipulate data.  This is the fundamental of SAS programming.

Ronein
Meteorite | Level 14

Thank you.

You are telling me to store the information in data set and then take distinct values.

But ,I get the data in parameter as I showed so we need to search for solution  from here.

There is no data set.

How can I create a data set from information in parameter?

 

PaigeMiller
Diamond | Level 26

Read it into a data set. Then manipulate it.

--
Paige Miller
Kurt_Bremser
Super User
data quarters (keep=quarter);
length quarter $4;
do i = 1 to countw("&param","+");
  quarter = scan("&param",i,"+");
  output;
end;
run;

and you got a nice dataset from which to work.

Ronein
Meteorite | Level 14

So now from the &vector parameter I created a data set.

Then I took the distinct values.

Now I need to create again a parameter with multiple values with + between them

I should I do the final step please?

%let vector=1807+1806+1712+1806;

data tbl1 (keep=YYMM);
length YYMM $4;
do i = 1 to countw("&vector","+");
  YYMM = scan("&vector",i,"+");
  output;
end;
run;

PROC SQL;
	create table tbl2 as
	select 	 distinct YYMM  
	from tbl1
;
QUIT;

/*Now I want to create a parameter called  &vector2 that will get the values in table tbl2 with + symbol between values*/
Kurt_Bremser
Super User

If you kept your data in a small dataset (which is the sensible thing to do) instead of a macro variable (which is usually not the smartest thing to do - I'm being polite here!), you'd only need a sort nodupkey or a select distinct.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 1203 views
  • 7 likes
  • 4 in conversation