IF, and that is a big if in many cases, the Name and Filenumber values you want have a single one value for the given id:
INTO is the instruction in SQL to place values into macro variables. Also not the use of : preceding the name of the macro variable. The distinct may be overkill but if you have multiple records with the same name and filenumber. I used different macro variable names so you can see where the macro variable appears easier. Data set variables and macro variables my get confused at some point and having different names sometimes helps follow code instead of "Name" appear in many places.
%let id=123456;
Proc sql noprint;
select distinct name, filenumber into : namevar, : numvar
from table1
where id = &id.;
quit;
Title1 "Report for &namevar. &numvar.";
If a variable is truly numeric you may want to control the conversion with a Put(numericvar, <someformat> -L) . The default conversion that SAS would use is a best12. format and the result will be right justified which can place a lot of spaces before your variable.
You can see that in this example where the first Age has a bunch of spaces in the output.
%let id=Alice;
Proc sql noprint;
select distinct sex, age, put(age,best5. -L) into: namevar, :numvar1, :numvar2
from sashelp.class
where name = "&id.";
quit;
%put Namevar=&namevar numvar1=&numvar1 numvar2=&numvar2;
... View more