BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

Do not convert NUMBERS (values of the CER variable) into STRINGS (value in the macro variable(s)) just to later try to convert them back into NUMBERS. 

 

To convert multiple observations into multiple variables you can use PROC TRANSPOSE.  For example if you sorted the data by ID and DATE you might want to generate one observation per ID instead of one observation per ID and DATE by using a PROC TRANSPOSE like this.  The PREFIX= option says to name the generated variables as TASAS1, TASAS2 , etc.

proc transpose data=desa.cer  out=want(drop=_name_) prefix=TASAS ;
  by id ;
  var cer ;
run;

But the PHOTOGRAPH you posted of your data does not look like it is properly organized for transposing.  Why the the observations all of different values of ID and DATE?

 

Also it looks like you are trying to subset data to just specific days in the year.  Which year? Or are there multiple years?   Does each ID have all of the years?

 

Here is simplified way to select those two days of the year (independent of which year) by using formats to convert the date values into strings you can test.  The PUT() function with the DDMMYY10 format converts dates into strings that look alot like the values in your posted photograph, only they will always use two digits for day and month.  The colon modifier on the equality test will match the string just to the length of the shorter of the two.  So just the DD/MM part of the result of the PUT() function.

where put(fecha,DDMMYY10.) in: ('22/01' '22/07') ;

Perhaps you don't need to define any ARRAYs at all for what you are trying to do.  If you create a series of variable that all have the same base name and numeric suffix with sequential values, like TASAS1, TASAS2 , ... then you can just reference them use a variable list where you need them in your code.

 

Remember that an ARRAY in SAS code is just a way to make it easy to reference many different variables by using an index into a list of the variable names.  Those references are only valid in the data step where the ARRAY is defined.  It is just a tool to make it so you can repeat similar statements without having to type "wallpaper" code.

 

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 16. 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
  • 15 replies
  • 7261 views
  • 3 likes
  • 5 in conversation