BookmarkSubscribeRSS Feed
RTelang
Fluorite | Level 6

data details;                                                                                                                             

   input start $ 1-2 label $50. ;                                                                                         

   datalines;   

1 AFGAN

2 MULTIPLE

3 OTHER

;

RUN;

am new to formats how can i create a macro with input dataset as parameter & create format from the dataset details!  help ?

11 REPLIES 11
Kurt_Bremser
Super User

You just need two additional columns in your dataset:

data details;
input start $ 1-2 label $50.;
fmtname = 'xnational';
type = 'C';
datalines;
1 AFGAN
2 MULTIPLE
3 OTHER
;
run;

proc format library=work cntlin=details;
run;

data want;
nationality = put("1",$xnational.);
run;
RTelang
Fluorite | Level 6
can i code this in a macro & how can i test it for all values in the details dataset?
data_null__
Jade | Level 19

Are you asking if you can use the FORMAT as a source for valid values for data cleaning?

Ksharp
Super User

No need for Macro.

 

data details;                                                                                                                             
   input start $ 1-2 label $50. ;
   fmtname='fmt'; 
   type='n';                                                                                        
   datalines;   
1 AFGAN
2 MULTIPLE
3 OTHER
;
RUN;
proc format cntlin=details;run;

data _NULL_;
 test=1; fmt=put(test,fmt.); putlog test= fmt=;
 test=2; fmt=put(test,fmt.); putlog test= fmt=;
 test=4; fmt=put(test,fmt.); putlog test= fmt=;
run;
RTelang
Fluorite | Level 6
@ xiabut the data is huge so need a macro %macro fmt(inds=);
Kurt_Bremser
Super User

No matter how big a dataset is, the code stays the same. NO need for a macro.

Unless you have other requirements that you did not mention.

RTelang
Fluorite | Level 6
ok let me rephrase %macro fmt(inds=); is my requirement to do the code.
Kurt_Bremser
Super User

What is the inds parameter in the macro? The dataset that contains the layout of the format, or the dataset that the format should be applied on?

 

RTelang
Fluorite | Level 6
DS that the format should be applied on?
Kurt_Bremser
Super User

Then you need more parameters. Which column(s) should which format be applied to?

In the end you may find that writing a macro that solves all cases will be more effort than simply writing the format assignments by hand.

Astounding
PROC Star

Unfortunately, you have a difficult task.  You will need to go back to the person who gave you the requirements and tell them that they have no idea what they are talking about.

 

If you look at output data sets based on a format, there are roughly 20 variables.  That means you will need roughly 20 parameters on such a macro, depending on which features of a format you would like to utilize.  There is no way that a single parameter can do that.  If you can narrow down the features that are needed, you can reduce the number of parameters.  But you have to start with a list of features.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 11 replies
  • 1322 views
  • 1 like
  • 5 in conversation