hi guys
I would like to create a macro or array to deal with columns called '0'n to '120'n.
I would like to introduce a loop or somenthing, like do i=0 to 120; but I can't manage to adapt it to this kind of expression ' ..number that gives the name to the column... 'n
Can you be bit more specific about what you wish to do?
Have tried something which didn't work, please attach any relevant log.
Inside a macro:
%local i;
%do i=0 %to 120;
%unquote(%str(%'&i%'n))
%end;
I might be inclined to use the nliteral function. Although my example has no basis in reality.:smileysilly:
Sorry guys I can't figure out to apply your statement to my real life situation
my real data have a structure like this:
data net_revenues;
infile cards dlm=',';
input type $ '1'n '2'n '3'n;
cards;
a,18,12,100
b,20,23,50
c,22,1,75
;
in real life I have many more columns so as I said I would like to avoid to repeat all the column name.
let's imagine a simple macro putting a proc freq of variable '1'n to '3'n? how would you adapt your code to this (in real life I would do thing more complex than proc freq, but it's just a workaround to speak of something easy).
thanks
Can you take a step back?
Why can't you simply name your variables N0, N1, ..., N120
This would make array processing and looping straight forward.
The variables can also just be given labels 0, 1, ..., 120
I did say it had no basis in reality. I think you just need to use a "SAS Variable List"
enumerated '1'n-'300'n
name range '1'n-numeric-'200'n
Here is code to input an arbitrary number of columns named with numbers.
I still have no idea why you would want to do this.
options validvarname=any;
%let first=1;
%let last=3;
data net_revenues;
infile cards dlm=',' truncover ;
input type $ "&first"n - "&last"n;
put (_all_) (=);
cards;
a,18,12,100
b,20,23,50
c,22,1,75
;
type=a 1=18 2=12 3=100
type=b 1=20 2=23 3=50
type=c 1=22 2=1 3=75
Why do you think that you need to use numbers for your variable names?
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.
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.